Exemplo n.º 1
0
        public static EastAsianWidthDictionary Create(System.IO.TextReader sr)
        {
            EastAsianWidthDictionary dic = new EastAsianWidthDictionary();

            System.Text.RegularExpressions.Regex reg
                = new System.Text.RegularExpressions.Regex(@"^(?<CODE1>[0-9A-F]+)(\.\.(?<CODE2>[0-9A-F]+))?;(?<WIDTH>(Na|N|W|F|H|A))\s");

            EastAsianWidthDictionary dictionary = new EastAsianWidthDictionary();

            string line;

            while (sr.Peek() != -1)
            {
                line = sr.ReadLine();
                if (line.StartsWith("#"))
                {
                    continue;
                }

                var match = reg.Match(line);
                if (match.Success)
                {
                    string          sw = match.Groups["WIDTH"].Value;
                    EastAsianWidths w  = EastAsianWidths.Unknown;
                    switch (sw[0])
                    {
                    case 'N': w = sw.Length == 1 ? EastAsianWidths.Neutral : EastAsianWidths.Narrow; break;

                    case 'W': w = EastAsianWidths.Wide; break;

                    case 'F': w = EastAsianWidths.FullWidth; break;

                    case 'H': w = EastAsianWidths.HalfWidth; break;

                    case 'A': w = EastAsianWidths.Ambiguous; break;

                    default: w = EastAsianWidths.Unknown; break;
                    }

                    int code1 = int.Parse(match.Groups["CODE1"].Value, System.Globalization.NumberStyles.HexNumber);
                    int code2 = code1;
                    if (match.Groups["CODE2"].Success)
                    {
                        code2 = int.Parse(match.Groups["CODE2"].Value, System.Globalization.NumberStyles.HexNumber);
                    }

                    Range r = new Range(w, code1, code2);

                    dic.List.Add(r);
                }
                else
                {
                }
            }
            return(dic);
        }
Exemplo n.º 2
0
 public Range(EastAsianWidths w, int code1, int code2)
 {
     this.Width = w;
     this.Code1 = code1;
     this.Code2 = code2;
 }