Esempio n. 1
0
    /**
     * @param result
     * @param convertCase
     * @param nextConvertCase
     */
    private static void checkMiddleChar(StringBuilder result, ConvertCase convertCase, ConvertCase nextConvertCase)
    {
        string latName = convertCase.getConvert();

        switch (latName.Length)
        {
        case LENGTH_2:
            result.Append(convertCase.isLowcase() ? latName.Substring(INDEX_1, LENGTH_1).ToLower() : nextConvertCase
                          .isLowcase() ? latName.Substring(INDEX_1, LENGTH_1) : latName.Substring(INDEX_1, LENGTH_1).ToUpper());
            if (convertCase.getConvert() == "ZZ" && nextConvertCase.getConvert() == "HH")
            {
                result.Append(nextConvertCase.isLowcase() ? "g" : "G");
            }
            break;

        case LENGTH_3:
            result.Append(convertCase.isLowcase() ? latName.Substring(INDEX_2, LENGTH_1).ToLower() : nextConvertCase
                          .isLowcase() ? latName.Substring(INDEX_2, LENGTH_1) : latName.Substring(INDEX_2, LENGTH_1).ToUpper());
            break;

        case LENGTH_4:
            result.Append(convertCase.isLowcase() ? latName.Substring(INDEX_2, LENGTH_2).ToLower() : nextConvertCase
                          .isLowcase() ? latName.Substring(INDEX_2, LENGTH_2) : latName.Substring(INDEX_2, LENGTH_2).ToUpper());
            break;

        case LENGTH_8:
            result.Append(convertCase.isLowcase() ? latName.Substring(INDEX_4, LENGTH_4).ToLower() : nextConvertCase
                          .isLowcase() ? latName.Substring(INDEX_4, LENGTH_4) : latName.Substring(INDEX_4, LENGTH_4).ToUpper());
            break;
        }
    }
Esempio n. 2
0
    public static string generateLat(string name)
    {
        StringBuilder result          = new StringBuilder();
        ConvertCase   prevConvertCase = null;

        for (int index = 0; index < name.Length; index += 1)
        {
            string curChar  = name.Substring(index, LENGTH_1);
            string nextChar = index == name.Length - 1 ? null : name.Substring(index + INDEX_1, LENGTH_1);
            if (new Regex("[-'’,]").IsMatch(curChar))
            {
                continue;
            }
            if (!cyrToLat.ContainsKey(curChar))
            {
                if (" " == curChar)
                {
                    prevConvertCase = null;
                    result.Append(' ');
                }
                continue;
            }
            ConvertCase convertCase = cyrToLat[curChar];
            if (prevConvertCase == null)
            {
                checkFirstChar(result, convertCase, nextChar != null && cyrToLat.ContainsKey(nextChar) ? cyrToLat[nextChar] : convertCase);
            }
            else
            {
                checkMiddleChar(result, convertCase, nextChar != null && cyrToLat.ContainsKey(nextChar) ? cyrToLat[nextChar] : convertCase);
            }
            prevConvertCase = convertCase;
        }
        return(result.ToString());
    }
Esempio n. 3
0
 static UkrainianToLatin()
 {
     cyrToLat = new Dictionary <string, ConvertCase>();
     foreach (KeyValuePair <string, string> item in convert)
     {
         cyrToLat[item.Value.Substring(INDEX_0, LENGTH_1)] = new ConvertCase(item.Key, false);
         cyrToLat[item.Value.Substring(INDEX_1, LENGTH_1)] = new ConvertCase(item.Key, true);
         if (item.Key == "EE")
         {
             cyrToLat["Ё"] = new ConvertCase(item.Key, false);
             cyrToLat["ё"] = new ConvertCase(item.Key, true);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Converts a string to the given attribute's value.
        /// </summary>
        /// <param name="attribute">This attribute.</param>
        /// <param name="value">The value to convert to an attribute value.</param>
        /// <returns>Returns the attribute's value converted from a string.</returns>
        /// <exception cref="ArgumentException">If the input string cannot be converted to the attribute's value.</exception>
        public static object FromString(this DictionaryAttribute attribute, string value)
        {
            switch (attribute)
            {
            case DictionaryAttribute.Separator:             return(Separator.FromString(value));

            case DictionaryAttribute.Encoding:              return(Encoding.FromString(value));

            case DictionaryAttribute.FrequencyIncluded:     return(FrequencyIncluded.FromString(value));

            case DictionaryAttribute.IgnoreNumbers:         return(IgnoreNumbers.FromString(value));

            case DictionaryAttribute.IgnorePunctuation:     return(IgnorePunctuation.FromString(value));

            case DictionaryAttribute.IgnoreCamelCase:       return(IgnoreCamelCase.FromString(value));

            case DictionaryAttribute.IgnoreAllUpperCase:    return(IgnoreAllUpperCase.FromString(value));

            case DictionaryAttribute.IgnoreDiacritics:      return(IgnoreDiacritics.FromString(value));

            case DictionaryAttribute.ConvertCase:           return(ConvertCase.FromString(value));

            case DictionaryAttribute.RunOnWords:            return(RunOnWords.FromString(value));

            case DictionaryAttribute.Culture:               return(Culture.FromString(value));

            case DictionaryAttribute.Encoder:               return(Encoder.FromString(value));

            case DictionaryAttribute.InputConversion:       return(InputConversion.FromString(value));

            case DictionaryAttribute.OutputConversion:      return(OutputConversion.FromString(value));

            case DictionaryAttribute.ReplacementPairs:      return(ReplacementPairs.FromString(value));

            case DictionaryAttribute.EquivalentChars:       return(EquivalentChars.FromString(value));

            case DictionaryAttribute.License:               return(License.FromString(value));

            case DictionaryAttribute.Author:                return(Author.FromString(value));

            case DictionaryAttribute.CreationDate:          return(CreationDate.FromString(value));
            }
            throw new ArgumentException($"No attribute for property: {nameof(attribute)}");
        }