@@ -98,12 +98,12 @@ public String metaphone(final String txt) {
9898 final char [] inwd = txt .toUpperCase (java .util .Locale .ENGLISH ).toCharArray ();
9999
100100 final StringBuilder local = new StringBuilder (40 ); // manipulate
101- final StringBuilder code = new StringBuilder (10 ); // output
101+ final StringBuilder code = new StringBuilder (10 ); // output
102102 // handle initial 2 characters exceptions
103- switch (inwd [0 ]) {
103+ switch (inwd [0 ]) {
104104 case 'K' :
105105 case 'G' :
106- case 'P' : /* looking for KN, etc*/
106+ case 'P' : /* looking for KN, etc */
107107 if (inwd [1 ] == 'N' ) {
108108 local .append (inwd , 1 , inwd .length - 1 );
109109 } else {
@@ -118,7 +118,7 @@ public String metaphone(final String txt) {
118118 }
119119 break ;
120120 case 'W' : /* looking for WR or WH */
121- if (inwd [1 ] == 'R' ) { // WR -> R
121+ if (inwd [1 ] == 'R' ) { // WR -> R
122122 local .append (inwd , 1 , inwd .length - 1 );
123123 break ;
124124 }
@@ -140,14 +140,13 @@ public String metaphone(final String txt) {
140140 final int wdsz = local .length ();
141141 int n = 0 ;
142142
143- while (code .length () < this .getMaxCodeLen () &&
144- n < wdsz ) { // max code size of 4 works well
143+ while (code .length () < this .getMaxCodeLen () && n < wdsz ) { // max code size of 4 works well
145144 final char symb = local .charAt (n );
146145 // remove duplicate letters except C
147- if (symb != 'C' && isPreviousChar ( local , n , symb ) ) {
146+ if (symb != 'C' && isPreviousChar (local , n , symb ) ) {
148147 n ++;
149148 } else { // not dup
150- switch (symb ) {
149+ switch (symb ) {
151150 case 'A' :
152151 case 'E' :
153152 case 'I' :
@@ -158,37 +157,30 @@ public String metaphone(final String txt) {
158157 }
159158 break ; // only use vowel if leading char
160159 case 'B' :
161- if ( isPreviousChar (local , n , 'M' ) &&
162- isLastChar (wdsz , n ) ) { // B is silent if word ends in MB
160+ if (isPreviousChar (local , n , 'M' ) && isLastChar (wdsz , n )) { // B is silent if word ends in MB
163161 break ;
164162 }
165163 code .append (symb );
166164 break ;
167165 case 'C' : // lots of C special cases
168166 /* discard if SCI, SCE or SCY */
169- if ( isPreviousChar (local , n , 'S' ) &&
170- !isLastChar (wdsz , n ) &&
171- FRONTV .indexOf (local .charAt (n + 1 )) >= 0 ) {
167+ if (isPreviousChar (local , n , 'S' ) && !isLastChar (wdsz , n ) && FRONTV .indexOf (local .charAt (n + 1 )) >= 0 ) {
172168 break ;
173169 }
174170 if (regionMatch (local , n , "CIA" )) { // "CIA" -> X
175171 code .append ('X' );
176172 break ;
177173 }
178- if (!isLastChar (wdsz , n ) &&
179- FRONTV .indexOf (local .charAt (n + 1 )) >= 0 ) {
174+ if (!isLastChar (wdsz , n ) && FRONTV .indexOf (local .charAt (n + 1 )) >= 0 ) {
180175 code .append ('S' );
181176 break ; // CI,CE,CY -> S
182177 }
183- if (isPreviousChar (local , n , 'S' ) &&
184- isNextChar (local , n , 'H' ) ) { // SCH->sk
178+ if (isPreviousChar (local , n , 'S' ) && isNextChar (local , n , 'H' )) { // SCH->sk
185179 code .append ('K' );
186180 break ;
187181 }
188182 if (isNextChar (local , n , 'H' )) { // detect CH
189- if (n == 0 &&
190- wdsz >= 3 &&
191- isVowel (local ,2 ) ) { // CH consonant -> K consonant
183+ if (n == 0 && wdsz >= 3 && isVowel (local , 2 )) { // CH consonant -> K consonant
192184 code .append ('K' );
193185 } else {
194186 code .append ('X' ); // CHvowel -> X
@@ -198,34 +190,26 @@ public String metaphone(final String txt) {
198190 }
199191 break ;
200192 case 'D' :
201- if (!isLastChar (wdsz , n + 1 ) &&
202- isNextChar (local , n , 'G' ) &&
203- FRONTV .indexOf (local .charAt (n + 2 )) >= 0 ) { // DGE DGI DGY -> J
204- code .append ('J' ); n += 2 ;
193+ if (!isLastChar (wdsz , n + 1 ) && isNextChar (local , n , 'G' ) && FRONTV .indexOf (local .charAt (n + 2 )) >= 0 ) { // DGE DGI DGY -> J
194+ code .append ('J' );
195+ n += 2 ;
205196 } else {
206197 code .append ('T' );
207198 }
208199 break ;
209200 case 'G' : // GH silent at end or before consonant
210- if (isLastChar (wdsz , n + 1 ) &&
211- isNextChar (local , n , 'H' )) {
201+ if (isLastChar (wdsz , n + 1 ) && isNextChar (local , n , 'H' )) {
212202 break ;
213203 }
214- if (!isLastChar (wdsz , n + 1 ) &&
215- isNextChar (local ,n ,'H' ) &&
216- !isVowel (local ,n +2 )) {
204+ if (!isLastChar (wdsz , n + 1 ) && isNextChar (local , n , 'H' ) && !isVowel (local , n + 2 )) {
217205 break ;
218206 }
219- if (n > 0 &&
220- ( regionMatch (local , n , "GN" ) ||
221- regionMatch (local , n , "GNED" ) ) ) {
207+ if (n > 0 && (regionMatch (local , n , "GN" ) || regionMatch (local , n , "GNED" ))) {
222208 break ; // silent G
223209 }
224210 // NOTE: Given that duplicated chars are removed, I don't see how this can ever be true
225211 hard = isPreviousChar (local , n , 'G' );
226- if (!isLastChar (wdsz , n ) &&
227- FRONTV .indexOf (local .charAt (n + 1 )) >= 0 &&
228- !hard ) {
212+ if (!isLastChar (wdsz , n ) && FRONTV .indexOf (local .charAt (n + 1 )) >= 0 && !hard ) {
229213 code .append ('J' );
230214 } else {
231215 code .append ('K' );
@@ -235,11 +219,10 @@ public String metaphone(final String txt) {
235219 if (isLastChar (wdsz , n )) {
236220 break ; // terminal H
237221 }
238- if (n > 0 &&
239- VARSON .indexOf (local .charAt (n - 1 )) >= 0 ) {
222+ if (n > 0 && VARSON .indexOf (local .charAt (n - 1 )) >= 0 ) {
240223 break ;
241224 }
242- if (isVowel (local ,n + 1 )) {
225+ if (isVowel (local , n + 1 )) {
243226 code .append ('H' ); // Hvowel
244227 }
245228 break ;
@@ -261,7 +244,7 @@ public String metaphone(final String txt) {
261244 }
262245 break ;
263246 case 'P' :
264- if (isNextChar (local ,n , 'H' )) {
247+ if (isNextChar (local , n , 'H' )) {
265248 // PH -> F
266249 code .append ('F' );
267250 } else {
@@ -272,37 +255,34 @@ public String metaphone(final String txt) {
272255 code .append ('K' );
273256 break ;
274257 case 'S' :
275- if (regionMatch (local ,n ,"SH" ) ||
276- regionMatch (local ,n ,"SIO" ) ||
277- regionMatch (local ,n ,"SIA" )) {
258+ if (regionMatch (local , n , "SH" ) || regionMatch (local , n , "SIO" ) || regionMatch (local , n , "SIA" )) {
278259 code .append ('X' );
279260 } else {
280261 code .append ('S' );
281262 }
282263 break ;
283264 case 'T' :
284- if (regionMatch (local ,n ,"TIA" ) ||
285- regionMatch (local ,n ,"TIO" )) {
265+ if (regionMatch (local , n , "TIA" ) || regionMatch (local , n , "TIO" )) {
286266 code .append ('X' );
287267 break ;
288268 }
289- if (regionMatch (local ,n , "TCH" )) {
269+ if (regionMatch (local , n , "TCH" )) {
290270 // Silent if in "TCH"
291271 break ;
292272 }
293273 // substitute numeral 0 for TH (resembles theta after all)
294- if (regionMatch (local ,n , "TH" )) {
274+ if (regionMatch (local , n , "TH" )) {
295275 code .append ('0' );
296276 } else {
297277 code .append ('T' );
298278 }
299279 break ;
300280 case 'V' :
301- code .append ('F' ); break ;
281+ code .append ('F' );
282+ break ;
302283 case 'W' :
303284 case 'Y' : // silent if not followed by vowel
304- if (!isLastChar (wdsz ,n ) &&
305- isVowel (local ,n +1 )) {
285+ if (!isLastChar (wdsz , n ) && isVowel (local , n + 1 )) {
306286 code .append (symb );
307287 }
308288 break ;
0 commit comments