File tree 2 files changed +10
-2
lines changed
main/java/org/apache/commons/codec/language
test/java/org/apache/commons/codec/language
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -275,7 +275,8 @@ public String nysiis(String str) {
275
275
276
276
// First character of key = first character of name.
277
277
final StringBuilder key = new StringBuilder (str .length ());
278
- key .append (str .charAt (0 ));
278
+ final char firstChar = str .charAt (0 );
279
+ key .append (firstChar );
279
280
280
281
// Transcode remaining characters, incrementing by one character each time
281
282
final char [] chars = str .toCharArray ();
@@ -314,6 +315,12 @@ public String nysiis(String str) {
314
315
if (lastChar == 'A' ) {
315
316
key .deleteCharAt (key .length () - 1 );
316
317
}
318
+
319
+ if (key .length ()==0 ){
320
+ // We've removed the first character of the string. Likely because it was na S or A
321
+ // We should return at least the first character
322
+ key .append (firstChar );
323
+ }
317
324
}
318
325
319
326
final String string = key .toString ();
Original file line number Diff line number Diff line change @@ -140,7 +140,8 @@ public void testDropBy() throws EncoderException {
140
140
new String [] { "JILES" , "JAL" },
141
141
// violates 6: if the last two characters are AY, remove A
142
142
new String [] { "CARRAWAY" , "CARY" }, // Original: CARAY
143
- new String [] { "YAMADA" , "YANAD" });
143
+ new String [] { "YAMADA" , "YANAD" },
144
+ new String [] { "ASH" , "A" });
144
145
}
145
146
146
147
@ Test
You can’t perform that action at this time.
0 commit comments