Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Utf32 #1

Open
Lazuplis-Mei opened this issue Mar 20, 2023 · 0 comments
Open

Utf32 #1

Lazuplis-Mei opened this issue Mar 20, 2023 · 0 comments

Comments

@Lazuplis-Mei
Copy link

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;
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant