Updated manual word count code to catter for apostrophes in words like John's
This commit is contained in:
parent
73bde4e2c3
commit
3058af87a9
|
@ -32,10 +32,10 @@ public class WordCounter {
|
|||
int characterCounter = 0;
|
||||
|
||||
while (characterCounter < stringLength) {
|
||||
if ((Character.isLetter(arg.charAt(characterCounter)) || isAllowedWordPunct(arg.charAt(characterCounter))) && flag == SEPARATOR) {
|
||||
if (isAllowedInWord(arg.charAt(characterCounter)) && flag == SEPARATOR) {
|
||||
flag = WORD;
|
||||
count++;
|
||||
} else if (!Character.isLetter(arg.charAt(characterCounter))) {
|
||||
} else if (!isAllowedInWord(arg.charAt(characterCounter))) {
|
||||
flag = SEPARATOR;
|
||||
}
|
||||
characterCounter++;
|
||||
|
@ -43,7 +43,7 @@ public class WordCounter {
|
|||
return count;
|
||||
}
|
||||
|
||||
private static boolean isAllowedWordPunct(char charAt) {
|
||||
return charAt == '\'';
|
||||
private static boolean isAllowedInWord(char charAt) {
|
||||
return charAt == '\'' || Character.isLetter(charAt);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue