Updated manual word count code to catter for apostrophes in words like John's

This commit is contained in:
alfred.samanga@gmail.com 2019-08-22 20:51:43 +02:00
parent 73bde4e2c3
commit 3058af87a9
1 changed files with 4 additions and 4 deletions

View File

@ -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);
}
}