private static bool NormalizeAndCheckString( string charString, int start, int length, Normalization form) { int i = start; var norm = new NormalizingCharacterInput( charString, start, length, form); var ch = 0; while ((ch = norm.ReadChar()) >= 0) { int c = charString[i]; if ((c & 0x1ffc00) == 0xd800 && i + 1 < charString.Length && charString[i + 1] >= 0xdc00 && charString[i + 1] <= 0xdfff) { // Get the Unicode code point for the surrogate pair c = 0x10000 + ((c - 0xd800) << 10) + (charString[i + 1] - 0xdc00); ++i; } else if ((c & 0x1ff800) == 0xd800) { // unpaired surrogate c = 0xfffd; } ++i; if (c != ch) { return false; } } return i == start + length; }
public static IList<int> GetChars(string str, Normalization form) { if (str == null) { throw new ArgumentNullException("str"); } IList<int> ret = new List<int>(); int ch; var input = new NormalizingCharacterInput(str, form); while ((ch = input.ReadChar()) >= 0) { ret.Add(ch); } return ret; }