From dab667ec92b00fdf211a833b3dc9c70c8ea690f3 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 25 Mar 2020 06:27:26 -0700 Subject: [PATCH] Added Encode without a range check --- BeefLibs/corlib/src/Text/UTF8.bf | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/BeefLibs/corlib/src/Text/UTF8.bf b/BeefLibs/corlib/src/Text/UTF8.bf index 87fd31e3..4d1f3c2d 100644 --- a/BeefLibs/corlib/src/Text/UTF8.bf +++ b/BeefLibs/corlib/src/Text/UTF8.bf @@ -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); + } + } } }