Beispiel #1
0
        public UnicodeSequence(string sequence)
        {
            if (sequence.Contains("-"))
            {
                var values = sequence.Split('-');

                if (values.Length == 2)
                {
                    Codepoint begin = new Codepoint(values[0]);
                    Codepoint end   = new Codepoint(values[1]);
                    if (end.Value < begin.Value)
                    {
                        throw new InvalidRangeException();
                    }
                    _codepoints = new Codepoint[end.Value - begin.Value + 1];
                    for (int i = 0; begin.Value + i <= end.Value; ++i)
                    {
                        _codepoints[i] = new Codepoint(begin.Value + i);
                    }
                }
                else
                {
                    throw new InvalidRangeException();
                }
            }
            else
            {
                var values = sequence.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                _codepoints = values.Select(x => new Codepoint(x)).ToArray();
            }
        }
Beispiel #2
0
        //either a single hex codepoint or two separated by a hyphen
        public Range(string range)
        {
            string[] values = range.Split(new[] { "-", "–", "—", ".." }, StringSplitOptions.RemoveEmptyEntries); //these are all different hyphens used on Wikipedia and in the UTR
            Begin = uint.Parse(values[0], System.Globalization.NumberStyles.HexNumber);

            if (values.Length == 1)
            {
                End = Begin;
            }
            else if (values.Length == 2)
            {
                End = uint.Parse(values[1], System.Globalization.NumberStyles.HexNumber);
            }
            else
            {
                throw new InvalidRangeException();
            }
        }
Beispiel #3
0
        // Either a single hex codepoint or two separated by a hyphen
        public Range(string range)
        {
            // These are all different hyphens used on Wikipedia and in the UTR
            var values = range.Split(RangeSplit, StringSplitOptions.RemoveEmptyEntries);

            Begin = UInt32.Parse(values[0], System.Globalization.NumberStyles.HexNumber);

            if (values.Length == 1)
            {
                End = Begin;
            }
            else if (values.Length == 2)
            {
                End = UInt32.Parse(values[1], System.Globalization.NumberStyles.HexNumber);
            }
            else
            {
                throw new InvalidRangeException();
            }
        }
Beispiel #4
0
 public bool Contains(Codepoint codepoint)
 {
     return(codepoint >= Begin && codepoint <= End);
 }
Beispiel #5
0
 public Range(Codepoint value)
 {
     Begin = value;
     End   = value;
 }
Beispiel #6
0
 public Range(Codepoint begin, Codepoint end)
 {
     Begin = begin;
     End   = end;
 }
Beispiel #7
0
 public bool Contains(Codepoint codepoint)
 {
     return(_ranges.Any(r => r.Contains(codepoint)));
 }
Beispiel #8
0
 public bool Contains(Codepoint codepoint)
 {
     return(codepoint.In(_codepoints));
 }