if (p2 < BmpThreshold)
{
res.Append(char.ConvertFromUtf32(p2));
}
else
{
var first = High + (p2 - BmpThreshold) / Offset;
var snd = Low + p2 % Offset;
res.Append((char)first).Append((char)snd);
}
I think this was unclear.
if p2 < BmpThreshold you can just (char)p2, and the else branch does exactly the same thing as char.ConvertFromUtf32.
You can use simple res.Append(char.ConvertFromUtf32(p2)) do all things.
And yourpublic static IEnumerable<int> ToCodePoints(this string str)can be replaced by
for (int i = 0; i < str.Length;)
{
int code = char.ConvertToUtf32(str, i++);
if (code >= BmpThreshold)
i++;
yield return code;
}
I think this was unclear.
if p2 < BmpThreshold you can just (char)p2, and the else branch does exactly the same thing as char.ConvertFromUtf32.
You can use simple
res.Append(char.ConvertFromUtf32(p2))do all things.And your
public static IEnumerable<int> ToCodePoints(this string str)can be replaced by