/// <summary> /// Handles 'R' cases. /// </summary> private int HandleR(string value, DoubleMetaphoneResult result, int index, bool slavoGermanic) { if (index == value.Length - 1 && !slavoGermanic && Contains(value, index - 2, 2, "IE") && !Contains(value, index - 4, 2, "ME", "MA")) { result.AppendAlternate('R'); } else { result.Append('R'); } return(CharAt(value, index + 1) == 'R' ? index + 2 : index + 1); }
/// <summary> /// Handles 'W' cases. /// </summary> private int HandleW(string value, DoubleMetaphoneResult result, int index) { if (Contains(value, index, 2, "WR")) { //-- can also be in middle of word --// result.Append('R'); index += 2; } else { if (index == 0 && (IsVowel(CharAt(value, index + 1)) || Contains(value, index, 2, "WH"))) { if (IsVowel(CharAt(value, index + 1))) { //-- Wasserman should match Vasserman --// result.Append('A', 'F'); } else { //-- need Uomo to match Womo --// result.Append('A'); } index++; } else if ((index == value.Length - 1 && IsVowel(CharAt(value, index - 1))) || Contains(value, index - 1, 5, "EWSKI", "EWSKY", "OWSKI", "OWSKY") || Contains(value, 0, 3, "SCH")) { //-- Arnow should match Arnoff --// result.AppendAlternate('F'); index++; } else if (Contains(value, index, 4, "WICZ", "WITZ")) { //-- Polish e.g. "filipowicz" --// result.Append("TS", "FX"); index += 4; } else { index++; } } return(index); }
/// <summary> /// Handles 'S' cases. /// </summary> private int HandleS(string value, DoubleMetaphoneResult result, int index, bool slavoGermanic) { if (Contains(value, index - 1, 3, "ISL", "YSL")) { //-- special cases "island", "isle", "carlisle", "carlysle" --// index++; } else if (index == 0 && Contains(value, index, 5, "SUGAR")) { //-- special case "sugar-" --// result.Append('X', 'S'); index++; } else if (Contains(value, index, 2, "SH")) { if (Contains(value, index + 1, 4, "HEIM", "HOEK", "HOLM", "HOLZ")) { //-- germanic --// result.Append('S'); } else { result.Append('X'); } index += 2; } else if (Contains(value, index, 3, "SIO", "SIA") || Contains(value, index, 4, "SIAN")) { //-- Italian and Armenian --// if (slavoGermanic) { result.Append('S'); } else { result.Append('S', 'X'); } index += 3; } else if ((index == 0 && Contains(value, index + 1, 1, "M", "N", "L", "W")) || Contains(value, index + 1, 1, "Z")) { //-- german & anglicisations, e.g. "smith" match "schmidt" // // "snider" match "schneider" --// //-- also, -sz- in slavic language although in hungarian it // // is pronounced "s" --// result.Append('S', 'X'); index = Contains(value, index + 1, 1, "Z") ? index + 2 : index + 1; } else if (Contains(value, index, 2, "SC")) { index = HandleSC(value, result, index); } else { if (index == value.Length - 1 && Contains(value, index - 2, 2, "AI", "OI")) { //-- french e.g. "resnais", "artois" --// result.AppendAlternate('S'); } else { result.Append('S'); } index = Contains(value, index + 1, 1, "S", "Z") ? index + 2 : index + 1; } return(index); }