GetType() public static method

Computes the type of the given character
public static GetType ( int ch ) : sbyte
ch int Character whose type is to be determined
return sbyte
Example #1
0
        // parses a list of MappingCharFilter style rules into a custom byte[] type table
        private sbyte[] ParseTypes(IEnumerable <string> rules)
        {
            IDictionary <char, sbyte> typeMap = new SortedDictionary <char, sbyte>();

            foreach (string rule in rules)
            {
                //Matcher m = typePattern.matcher(rule);
                //if (!m.find())
                Match m = typePattern.Match(rule);
                if (!m.Success)
                {
                    throw new System.ArgumentException("Invalid Mapping Rule : [" + rule + "]");
                }
                string lhs = ParseString(m.Groups[1].Value.Trim());
                sbyte  rhs = ParseType(m.Groups[2].Value.Trim());
                if (lhs.Length != 1)
                {
                    throw new System.ArgumentException("Invalid Mapping Rule : [" + rule + "]. Only a single character is allowed.");
                }
                if (rhs == WordDelimiterFilter.NOT_SET)
                {
                    throw new System.ArgumentException("Invalid Mapping Rule : [" + rule + "]. Illegal type.");
                }
                typeMap[lhs[0]] = rhs;
            }

            // ensure the table is always at least as big as DEFAULT_WORD_DELIM_TABLE for performance
            sbyte[] types = new sbyte[Math.Max(typeMap.Keys.LastOrDefault() + 1, WordDelimiterIterator.DEFAULT_WORD_DELIM_TABLE.Length)];
            for (int i = 0; i < types.Length; i++)
            {
                types[i] = WordDelimiterIterator.GetType(i);
            }
            foreach (var mapping in typeMap)
            {
                types[mapping.Key] = mapping.Value;
            }
            return(types);
        }