Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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