boolean doSort = true;
for(String s : ss) {
s = s.replaceAll("\\s+", " ");
TokenSequence t = Tokeniser.getInstance().tokenise(s);
for(int i=0;i<t.size();i++) {
Token token = t.getToken(i);
if(token.getValue().equalsIgnoreCase(word1)) {
for(int j=i+1;j<t.size() && j<i+10;j++) {
Token token2 = t.getToken(j);
if(token2.getValue().equalsIgnoreCase(word2)) {
int wstart1 = token.getStart();
int wend1 = token.getEnd();
int wstart2 = token2.getStart();
int wend2 = token2.getEnd();
String before = null;
if(wstart1 < beforeWidth) {
before = StringTools.multiplyString(" ", beforeWidth - wstart1) + s.substring(0, wstart1);
} else {
before = s.substring(wstart1 - beforeWidth, wstart1);
}
String after = null;
if(s.length() - wend2 > afterWidth) {
after = s.substring(wend2, wend2 + afterWidth);
} else {
after = s.substring(wend2);
}
String middle = s.substring(wend1, wstart2);
String middleDisplay = middle;
if(middle.length() > middleWidth) continue;
if(middle.length() < middleWidth) {
if(mode.startsWith("left")) {
middleDisplay += StringTools.multiplyString(" ", middleWidth - middle.length());
} else if(mode.startsWith("right")) {
middleDisplay = StringTools.multiplyString(" ", middleWidth - middle.length()) + middleDisplay;
} else {
int toPad = middleWidth - middle.length();
int left = toPad / 2;
int right = toPad - left;
middleDisplay = StringTools.multiplyString(" ", left) +
middleDisplay + StringTools.multiplyString(" ", right);
}
}
String display = before + " " + token.getValue() + " " + middleDisplay + " " + token2.getValue() + " " + after;
String sort = "";
if("interleave".equals(mode)) {
sort = middleDisplay.toLowerCase() + interleave(before, after, true);
} else if("left".equals(mode)) {
StringBuffer sb = new StringBuffer(before.toLowerCase());