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(); } }
//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(); } }
// 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(); } }
public bool Contains(Codepoint codepoint) { return(codepoint >= Begin && codepoint <= End); }
public Range(Codepoint value) { Begin = value; End = value; }
public Range(Codepoint begin, Codepoint end) { Begin = begin; End = end; }
public bool Contains(Codepoint codepoint) { return(_ranges.Any(r => r.Contains(codepoint))); }
public bool Contains(Codepoint codepoint) { return(codepoint.In(_codepoints)); }