Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODEC-281: Double metaphone encode kc as K #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -132,8 +132,7 @@ public String doubleMetaphone(String value, final boolean alternate) {
index = handleJ(value, result, index, slavoGermanic);
break;
case 'K':
result.append('K');
index = charAt(value, index + 1) == 'K' ? index + 2 : index + 1;
index = handleK(value, result, index);
break;
case 'L':
index = handleL(value, result, index);
Expand Down Expand Up @@ -543,6 +542,25 @@ private int handleJ(final String value, final DoubleMetaphoneResult result, int
return index;
}

/**
* Handles 'K' cases.
*/
private int handleK(final String value, final DoubleMetaphoneResult result, int index) {
result.append('K');
if (charAt(value, index + 1) == 'K') {
index += 2;
} else if ((charAt(value, index + 1) == 'C')) { //-- in "Kirkcaldy", "kc" should be encoded "K" instead of "KK" --//
final DoubleMetaphoneResult nextCharResult = new DoubleMetaphoneResult(this.getMaxCodeLen());
int nextCharIndex = handleC(value, nextCharResult, index + 1);
if (nextCharResult.getPrimary().equals("K")) {
index = nextCharIndex;
}
} else {
index++;
}
return index;
}

/**
* Handles 'L' cases.
*/
Expand Down
Expand Up @@ -512,6 +512,7 @@ public class DoubleMetaphone2Test extends StringEncoderAbstractTest<DoubleMetaph
{"King", "KNK", "KNK"},
{"Kinsey", "KNS", "KNS"},
{"Kirk", "KRK", "KRK"},
{"Kirkcaldy", "KRKL", "KRKL"},
{"Kirton", "KRTN", "KRTN"},
{"Kistler", "KSTL", "KSTL"},
{"Kitchen", "KXN", "KXN"},
Expand Down