File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
main/java/org/apache/commons/codec/language
test/java/org/apache/commons/codec/language Expand file tree Collapse file tree 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) {
275275
276276 // First character of key = first character of name.
277277 final StringBuilder key = new StringBuilder (str .length ());
278- key .append (str .charAt (0 ));
278+ final char firstChar = str .charAt (0 );
279+ key .append (firstChar );
279280
280281 // Transcode remaining characters, incrementing by one character each time
281282 final char [] chars = str .toCharArray ();
@@ -314,6 +315,12 @@ public String nysiis(String str) {
314315 if (lastChar == 'A' ) {
315316 key .deleteCharAt (key .length () - 1 );
316317 }
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+ }
317324 }
318325
319326 final String string = key .toString ();
Original file line number Diff line number Diff line change @@ -140,7 +140,8 @@ public void testDropBy() throws EncoderException {
140140 new String [] { "JILES" , "JAL" },
141141 // violates 6: if the last two characters are AY, remove A
142142 new String [] { "CARRAWAY" , "CARY" }, // Original: CARAY
143- new String [] { "YAMADA" , "YANAD" });
143+ new String [] { "YAMADA" , "YANAD" },
144+ new String [] { "ASH" , "A" });
144145 }
145146
146147 @ Test
You can’t perform that action at this time.
0 commit comments