1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Added Encode without a range check

This commit is contained in:
Brian Fiete 2020-03-25 06:27:26 -07:00
parent b5815927ef
commit dab667ec92

View file

@ -150,5 +150,32 @@ namespace System.Text
}
return len;
}
public static void Encode(char32 c, ref char8* dest)
{
if (c < (char32)0x80)
{
*dest++ = (char8)c;
}
else if (c < (char32)0x800)
{
*dest++ = (.)(((uint32)c >> 6) | 0xC0);
*dest++ = (.)(((uint32)c & 0x3F) | 0x80);
}
else if (c < (char32)0x10000)
{
*dest++ = (.)(((uint32)c >> 12) | 0xE0);
*dest++ = (.)((((uint32)c >> 6) & 0x3F) | 0x80);
*dest++ = (.)(((uint32)c & 0x3F) | 0x80);
}
else if (c < (char32)0x110000)
{
*dest++ = (.)(((uint32)c >> 18) | 0xF0);
*dest++ = (.)((((uint32)c >> 12) & 0x3F) | 0x80);
*dest++ = (.)((((uint32)c >> 6) & 0x3F) | 0x80);
*dest++ = (.)(((uint32)c & 0x3F) | 0x80);
}
}
}
}