public static string Filter(this string value, FilterAction matchRule, UnicodeCategory categories)
 {
     return new string((from c in value
                        where matchRule == FilterAction.Keep
                                  ? categories.HasFlag(Char.GetUnicodeCategory(c))
                                  : !categories.HasFlag(Char.GetUnicodeCategory(c))
                        select c).ToArray());
 }
Beispiel #2
0
 public static string Filter(this string value, FilterAction matchRule, UnicodeCategory categories)
 {
     return(new string(
                (
                    from c in value
                    where matchRule == FilterAction.Keep
                                         ? categories.HasFlag(char.GetUnicodeCategory(c))
                                         : !categories.HasFlag(char.GetUnicodeCategory(c))
                    select c).ToArray()));
 }
Beispiel #3
0
        /// <summary>
        /// Method to determine if a character is within those deemed of interest
        /// </summary>
        /// <param name="characterUnderTest">The character for which interest is being determined</param>
        /// <param name="categoriesOfInterest">The categories of characters that have been deemed interesting</param>
        /// <param name="setNameMatch">Optional word expected to be found in the character set name if it is of interest</param>
        /// <returns>Boolean true if the character meets the match rules, otherwise false</returns>
        private bool IsOfInterest(char characterUnderTest, UnicodeCategory categoriesOfInterest, string setNameMatch)
        {
            int codePoint;

            System.Unicode.UnicodeCharInfo unicodeInfo;

            // Start by checking if the character is within the categories that are of interest
            if (categoriesOfInterest.HasFlag(CharUnicodeInfo.GetUnicodeCategory(characterUnderTest)))
            {
                // Check if a set name match has been requested
                if (string.IsNullOrEmpty(setNameMatch))
                {
                    // No set name match required; it's a match
                    return(true);
                }

                // Perform matching of the name of the set in which the character resides
                codePoint   = Convert.ToInt32(characterUnderTest);
                unicodeInfo = System.Unicode.UnicodeInfo.GetCharInfo(codePoint);
                if (unicodeInfo.Block.Contains(setNameMatch))
                {
                    return(true);
                }
            }

            return(false);
        }