Exemple #1
0
        /// <summary>
        /// Trim and replace multiple spaces with a single space
        /// </summary>
        /// <param name="string">String to clean</param>
        /// <returns>Cleaned up string</returns>
        public static String Clean(this String @string)
        {
            if (@string is null)
            {
                throw new ArgumentNullException(nameof(@string));
            }
            StringBuilder Result  = new StringBuilder();
            Boolean       AtSpace = false;

            foreach (Char C in @string)
            {
                if (Char.GetUnicodeCategory(C) == UnicodeCategory.SpaceSeparator)
                {
                    if (!AtSpace)
                    {
                        AtSpace = true;
                        _       = Result.Append(' ');
                    }
                }
                else
                {
                    AtSpace = false;
                    _       = Result.Append(C);
                }
            }
            return(Result.ToString().Trim());
        }
Exemple #2
0
        static bool In(this char source, UnicodeCategory[] categories)
        {
            bool rc = false;

            var category = Char.GetUnicodeCategory(source);

            foreach (UnicodeCategory current in categories)
            {
                if (current == category)
                {
                    rc = true;
                    break;
                }
            }

            return(rc);
        }
 public static UnicodeCategory GetUnicodeCategory(this Char c)
 {
     return(Char.GetUnicodeCategory(c));
 }
Exemple #4
0
 /// <summary>
 /// Categorizes a specified Unicode character into a group identified by one of the <see cref="UnicodeCategory"/> values.
 /// </summary>
 /// <param name="Char">The Unicode character to categorize.</param>
 /// <returns>A <see cref="UnicodeCategory"/> value that identifies the group that contains <paramref name="Char"/>.</returns>
 public static UnicodeCategory GetUnicodeCategory(this Char Char) => Char.GetUnicodeCategory(Char);