@@ -320,8 +320,11 @@ public String colognePhonetic(String text) {
320320
321321 char nextChar ;
322322
323- char lastChar = '-' ;
324- char lastCode = '/' ;
323+ final char CHAR_FIRST_POS = '/' ; // are we processing the first character?
324+ final char CHAR_IGNORE = '-' ; // is this character to be ignored?
325+
326+ char lastChar = CHAR_IGNORE ;
327+ char lastCode = CHAR_FIRST_POS ;
325328 char code ;
326329 char chr ;
327330
@@ -331,16 +334,16 @@ public String colognePhonetic(String text) {
331334 if (input .length () > 0 ) {
332335 nextChar = input .getNextChar ();
333336 } else {
334- nextChar = '-' ;
337+ nextChar = CHAR_IGNORE ;
335338 }
336339
337340 if (arrayContains (AEIJOUY , chr )) {
338341 code = '0' ;
339342 } else if (chr == 'H' || chr < 'A' || chr > 'Z' ) {
340- if (lastCode == '/' ) {
341- continue ;
343+ if (lastCode == CHAR_FIRST_POS ) {
344+ continue ; // ignore leading unwanted characters
342345 }
343- code = '-' ;
346+ code = CHAR_IGNORE ;
344347 } else if (chr == 'B' || (chr == 'P' && nextChar != 'H' )) {
345348 code = '1' ;
346349 } else if ((chr == 'D' || chr == 'T' ) && !arrayContains (SCZ , nextChar )) {
@@ -355,7 +358,7 @@ public String colognePhonetic(String text) {
355358 } else if (chr == 'S' || chr == 'Z' ) {
356359 code = '8' ;
357360 } else if (chr == 'C' ) {
358- if (lastCode == '/' ) {
361+ if (lastCode == CHAR_FIRST_POS ) {
359362 if (arrayContains (AHKLOQRUX , nextChar )) {
360363 code = '4' ;
361364 } else {
@@ -378,9 +381,10 @@ public String colognePhonetic(String text) {
378381 code = '6' ;
379382 } else {
380383 code = chr ;
384+ throw new RuntimeException ();
381385 }
382386
383- if (code != '-' && (lastCode != code && (code != '0' || lastCode == '/' ) || code < '0' || code > '8' )) {
387+ if (code != CHAR_IGNORE && (lastCode != code && (code != '0' || lastCode == CHAR_FIRST_POS ) || code < '0' || code > '8' )) {
384388 output .addRight (code );
385389 }
386390
0 commit comments