Fixed a bug in findWord method

This commit is contained in:
Varun Upadhyay
2018-11-01 18:18:10 -07:00
committed by GitHub
parent 18d7252bdf
commit 085825e149

View File

@@ -11,11 +11,14 @@ public class WordIndexer {
String lowerCaseTextString = textString.toLowerCase();
String lowerCaseWord = word.toLowerCase();
while(index != -1){
index = lowerCaseTextString.indexOf(lowerCaseWord, index + 1);
if (index != -1) {
indexes.add(index);
while(index != -1) {
index = lowerCaseTextString.indexOf(lowerCaseWord, index);
if (index == -1) {
break;
}
indexes.add(index);
index++;
}
return indexes;
}