ToUnified() public static method

Unifies the string.
public static ToUnified ( string str ) : string
str string
return string
Esempio n. 1
0
        private static void AddCulture(CultureInfo culture)
        {
            lock (locker)
            {
                if (culture == null || Parsings.ContainsKey(culture))
                {
                    return;
                }

                Parsings[culture] = new Dictionary <string, byte>();

                for (byte m = 1; m <= 12; m++)
                {
                    var full = Parsing.ToUnified(culture.DateTimeFormat.GetAbbreviatedMonthName(m));
                    var shrt = Parsing.ToUnified(culture.DateTimeFormat.GetMonthName(m));

                    if (!Parsings[CultureInfo.InvariantCulture].ContainsKey(full))
                    {
                        Parsings[culture][full] = m;
                    }
                    if (!Parsings[CultureInfo.InvariantCulture].ContainsKey(shrt))
                    {
                        Parsings[culture][shrt] = m;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>Converts the string to a yes-no.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">
        /// A string containing a yes-no to convert.
        /// </param>
        /// <param name="formatProvider">
        /// The specified format provider.
        /// </param>
        /// <param name="result">
        /// The result of the parsing.
        /// </param>
        /// <returns>
        /// True if the string was converted successfully, otherwise false.
        /// </returns>
        public static bool TryParse(string s, IFormatProvider formatProvider, out YesNo result)
        {
            result = Empty;
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }
            var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture;

            if (Qowaiv.Unknown.IsUnknown(s, culture))
            {
                result = Unknown;
                return(true);
            }
            AddCulture(culture);

            var str = Parsing.ToUnified(s);

            if (Parsings[culture].TryGetValue(str, out byte val) ||
                Parsings[CultureInfo.InvariantCulture].TryGetValue(str, out val))
            {
                result = new YesNo {
                    m_Value = val
                };
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>Returns true if the val represents a valid month, otherwise false.</summary>
        public static bool IsValid(string val, IFormatProvider formatProvider)
        {
            var culture = formatProvider as CultureInfo;

            AddCulture(culture);

            var str = Parsing.ToUnified(val);

            return
                (Pattern.IsMatch(val ?? string.Empty) ||
                 (culture != null && Parsings[culture].ContainsKey(str)) ||
                 Parsings[CultureInfo.InvariantCulture].ContainsKey(str));
        }
Esempio n. 4
0
        /// <summary>Converts the string to a month.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">
        /// A string containing a month to convert.
        /// </param>
        /// <param name="formatProvider">
        /// The specified format provider.
        /// </param>
        /// <param name="result">
        /// The result of the parsing.
        /// </param>
        /// <returns>
        /// True if the string was converted successfully, otherwise false.
        /// </returns>
        public static bool TryParse(string s, IFormatProvider formatProvider, out Month result)
        {
            result = Month.Empty;
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }
            var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture;

            if (Qowaiv.Unknown.IsUnknown(s, culture))
            {
                result = Month.Unknown;
                return(true);
            }
            if (Pattern.IsMatch(s))
            {
                result = new Month()
                {
                    m_Value = Byte.Parse(s, formatProvider)
                };
                return(true);
            }
            else
            {
                AddCulture(culture);

                Byte m;
                var  str = Parsing.ToUnified(s);
                if (Parsings[culture].TryGetValue(str, out m) ||
                    Parsings[CultureInfo.InvariantCulture].TryGetValue(str, out m))
                {
                    result = new Month()
                    {
                        m_Value = m
                    };
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        /// <summary>Converts the string to a Gender.
        /// A return value indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="s">
        /// A string containing a Gender to convert.
        /// </param>
        /// <param name="formatProvider">
        /// The specified format provider.
        /// </param>
        /// <param name="result">
        /// The result of the parsing.
        /// </param>
        /// <returns>
        /// True if the string was converted successfully, otherwise false.
        /// </returns>
        public static bool TryParse(string s, IFormatProvider formatProvider, out Gender result)
        {
            result = Empty;
            if (string.IsNullOrEmpty(s))
            {
                return(true);
            }
            var c = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture;

            AddCulture(c);

            var str = Parsing.ToUnified(s);

            if (Parsings[c].TryGetValue(str, out byte val) || Parsings[CultureInfo.InvariantCulture].TryGetValue(str, out val))
            {
                result = new Gender {
                    m_Value = val
                };
                return(true);
            }
            return(false);
        }