Exemplo n.º 1
0
 /**
  * Handles 'L' cases
  */
 private int HandleL(string value, DoubleMetaphoneResult result, int index)
 {
     // PIN: do not add another L if the last added character was also a L
     if (!result.GetPrimary().ToUpper().EndsWith("L"))
     {
         result.Append('L');
     }
     // PIN: Todo: handle spanish e.g. 'cabrillo', 'gallegos'
     // one example can be found here: http://swoodbridge.com/DoubleMetaPhone/double_metaphone_func_1-01.txt
     if (CharAt(value, index + 1) == 'L')
     {
         if (ConditionL0(value, index))
         {
             result.AppendAlternate(' ');
         }
         index += 2;
     }
     else
     {
         index++;
     }
     return(index);
 }
Exemplo n.º 2
0
 /**
  * Handles 'L' cases
  */
 private int HandleL(string value, DoubleMetaphoneResult result, int index)
 {
     // PIN: do not add another L if the last added character was also a L
     if (!result.GetPrimary().ToUpper().EndsWith("L")) {
         result.Append('L');
     }
     // PIN: Todo: handle spanish e.g. 'cabrillo', 'gallegos'
     // one example can be found here: http://swoodbridge.com/DoubleMetaPhone/double_metaphone_func_1-01.txt
     if (CharAt(value, index + 1) == 'L')
     {
         if (ConditionL0(value, index))
         {
             result.AppendAlternate(' ');
         }
         index += 2;
     }
     else
     {
         index++;
     }
     return index;
 }
Exemplo n.º 3
0
        /**
         * Encode a value with Double Metaphone, optionally using the alternate
         * encoding.
         *
         * @param value string to encode
         * @param alternate use alternate encode
         * @return an encoded string
         */
        public string Encode(string value, bool alternate)
        {
            value = CleanInput(value);
            if (value == null)
            {
                return null;
            }

            bool slavoGermanic = IsSlavoGermanic(value);
            int index = IsSilentStart(value) ? 1 : 0;

            DoubleMetaphoneResult result = new DoubleMetaphoneResult(this.GetMaxCodeLen(), this);

            while (!result.IsComplete() && index <= value.Length - 1)
            {
                switch (value[index])
                {
                    case 'A':
                    case 'E':
                    case 'I':
                    case 'O':
                    case 'U':
                    case 'Y':
                    case 'À':
                    case 'Á':
                    case 'Â':
                    case 'Ã':
                    case 'Ä':
                    case 'Å':
                    case 'Æ':
                    case 'È':
                    case 'É':
                    case 'Ê':
                    case 'Ë':
                    case 'Ì':
                    case 'Í':
                    case 'Î':
                    case 'Ï':
                    case 'Ò':
                    case 'Ó':
                    case 'Ô':
                    case 'Õ':
                    case 'Ö':
                    case 'Ø':
                    case 'Ù':
                    case 'Ú':
                    case 'Û':
                    case 'Ü':
                    case 'Ý':
                        index = HandleAEIOUY(value, result, index);
                        break;
                    case 'B':
                        result.Append('P');
                        index = CharAt(value, index + 1) == 'B' ? index + 2 : index + 1;
                        break;
                    case '\u00C7':
                        // A C with a Cedilla
                        result.Append('S');
                        index++;
                        break;
                    case 'C':
                        index = HandleC(value, result, index);
                        break;
                    case 'D':
                        index = HandleD(value, result, index);
                        break;
                    case 'F':
                        index = HandleF(value, result, index);
                        break;
                    case 'G':
                        index = HandleG(value, result, index, slavoGermanic);
                        break;
                    case 'H':
                        index = HandleH(value, result, index);
                        break;
                    case 'J':
                        index = HandleJ(value, result, index, slavoGermanic);
                        break;
                    case 'K':
                        result.Append('K');
                        index = CharAt(value, index + 1) == 'K' ? index + 2 : index + 1;
                        break;
                    case 'L':
                        index = HandleL(value, result, index);
                        break;
                    case 'M':
                        result.Append('M');
                        index = ConditionM0(value, index) ? index + 2 : index + 1;
                        break;
                    case 'N':
                        result.Append('N');
                        index = CharAt(value, index + 1) == 'N' ? index + 2 : index + 1;
                        break;
                    case '\u00D1':
                        // N with a tilde (spanish ene)
                        result.Append('N');
                        index++;
                        break;
                    case 'P':
                        index = HandleP(value, result, index);
                        break;
                    case 'Q':
                        result.Append('K');
                        index = CharAt(value, index + 1) == 'Q' ? index + 2 : index + 1;
                        break;
                    case 'R':
                        index = HandleR(value, result, index, slavoGermanic);
                        break;
                    case 'S':
                        index = HandleS(value, result, index, slavoGermanic);
                        break;
                    case 'T':
                        index = HandleT(value, result, index);
                        break;
                    case 'V':
                        index = HandleV(value, result, index);
                        break;
                    case 'W':
                        index = HandleW(value, result, index);
                        break;
                    case 'X':
                        index = HandleX(value, result, index);
                        break;
                    case 'Z':
                        index = HandleZ(value, result, index, slavoGermanic);
                        break;
                    default:
                        index++;
                        break;
                }
            }

            return alternate ? result.GetAlternate() : result.GetPrimary();
        }
Exemplo n.º 4
0
        /**
         * Encode a value with Double Metaphone, optionally using the alternate
         * encoding.
         *
         * @param value string to encode
         * @param alternate use alternate encode
         * @return an encoded string
         */
        public string Encode(string value, bool alternate)
        {
            value = CleanInput(value);
            if (value == null)
            {
                return(null);
            }

            bool slavoGermanic = IsSlavoGermanic(value);
            int  index         = IsSilentStart(value) ? 1 : 0;

            DoubleMetaphoneResult result = new DoubleMetaphoneResult(this.GetMaxCodeLen(), this);

            while (!result.IsComplete() && index <= value.Length - 1)
            {
                switch (value[index])
                {
                case 'A':
                case 'E':
                case 'I':
                case 'O':
                case 'U':
                case 'Y':
                case 'À':
                case 'Á':
                case 'Â':
                case 'Ã':
                case 'Ä':
                case 'Å':
                case 'Æ':
                case 'È':
                case 'É':
                case 'Ê':
                case 'Ë':
                case 'Ì':
                case 'Í':
                case 'Î':
                case 'Ï':
                case 'Ò':
                case 'Ó':
                case 'Ô':
                case 'Õ':
                case 'Ö':
                case 'Ø':
                case 'Ù':
                case 'Ú':
                case 'Û':
                case 'Ü':
                case 'Ý':
                    index = HandleAEIOUY(value, result, index);
                    break;

                case 'B':
                    result.Append('P');
                    index = CharAt(value, index + 1) == 'B' ? index + 2 : index + 1;
                    break;

                case '\u00C7':
                    // A C with a Cedilla
                    result.Append('S');
                    index++;
                    break;

                case 'C':
                    index = HandleC(value, result, index);
                    break;

                case 'D':
                    index = HandleD(value, result, index);
                    break;

                case 'F':
                    index = HandleF(value, result, index);
                    break;

                case 'G':
                    index = HandleG(value, result, index, slavoGermanic);
                    break;

                case 'H':
                    index = HandleH(value, result, index);
                    break;

                case 'J':
                    index = HandleJ(value, result, index, slavoGermanic);
                    break;

                case 'K':
                    result.Append('K');
                    index = CharAt(value, index + 1) == 'K' ? index + 2 : index + 1;
                    break;

                case 'L':
                    index = HandleL(value, result, index);
                    break;

                case 'M':
                    result.Append('M');
                    index = ConditionM0(value, index) ? index + 2 : index + 1;
                    break;

                case 'N':
                    result.Append('N');
                    index = CharAt(value, index + 1) == 'N' ? index + 2 : index + 1;
                    break;

                case '\u00D1':
                    // N with a tilde (spanish ene)
                    result.Append('N');
                    index++;
                    break;

                case 'P':
                    index = HandleP(value, result, index);
                    break;

                case 'Q':
                    result.Append('K');
                    index = CharAt(value, index + 1) == 'Q' ? index + 2 : index + 1;
                    break;

                case 'R':
                    index = HandleR(value, result, index, slavoGermanic);
                    break;

                case 'S':
                    index = HandleS(value, result, index, slavoGermanic);
                    break;

                case 'T':
                    index = HandleT(value, result, index);
                    break;

                case 'V':
                    index = HandleV(value, result, index);
                    break;

                case 'W':
                    index = HandleW(value, result, index);
                    break;

                case 'X':
                    index = HandleX(value, result, index);
                    break;

                case 'Z':
                    index = HandleZ(value, result, index, slavoGermanic);
                    break;

                default:
                    index++;
                    break;
                }
            }

            return(alternate ? result.GetAlternate() : result.GetPrimary());
        }