Skip to content

Utf32 #1

@Lazuplis-Mei

Description

@Lazuplis-Mei
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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions