private static Rune[] UncheckedToRuneArray(string value, int start, int amount) { if (start < 0 || start > value.Length) { throw new ArgumentOutOfRangeException("start"); } if (amount < 0 || start + amount > value.Length) { throw new ArgumentOutOfRangeException("amount"); } var runes = new Rune[amount]; int index = 0; var decoder = new Utf16.CharDecoder(); bool result = true; for (int i = start; i < amount; i++) { var utf32 = decoder.Process(value[i]); if (utf32 != null) { runes[index++] = (Rune)utf32.GetValueOrDefault(); } } if (!result) { throw new RuneException(Utf16.MissingTrailingSurrogateMessage()); } if (index < runes.Length) { Array.Resize(ref runes, index); } return(runes); }
private static IEnumerable <Rune> UncheckedToRunes(string value, int start, int amount) { if (start < 0 || start > value.Length) { throw new ArgumentOutOfRangeException("start"); } if (amount < 0 || start + amount > value.Length) { throw new ArgumentOutOfRangeException("amount"); } var runes = new Rune[amount]; var decoder = new Utf16.CharDecoder(); bool result = true; for (int i = start; i < amount; i++) { var utf32 = decoder.Process(value[i]); if (utf32 != null) { yield return((Rune)utf32.GetValueOrDefault()); } } if (!result) { throw new RuneException(Utf16.MissingTrailingSurrogateMessage()); } }
// char... -> Rune... public static IEnumerable <Rune> ToRunes(this IEnumerable <char> chars) { var decoder = new Utf16.CharDecoder(); return(DecodeValues(chars, decoder, Utf16.MissingTrailingSurrogateMessage())); }