[libc-commits] [libc] [libc] Add UTF-16 support in CharacterConverter [1/6] (PR #230434)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Oct 13 15:58:47 PDT 2026
================
@@ -127,6 +194,57 @@ LIBC_INLINE int CharacterConverter::push(char8_t utf8_byte) {
return EILSEQ;
}
+LIBC_INLINE int CharacterConverter::push(char16_t utf16) {
+ // Checking for high surrogate if first push
+ if (isEmpty()) {
+ bool is_surrogate = (utf16 & 0xF800) == 0xD800;
----------------
michaelrj-google wrote:
here and below, we want to avoid "Magic Numbers" which are usually integer constants used in the code with no explanation or context. In this line both `0xF800` and `0xD800` are magic numbers. Generally the easiest way to avoid magic numbers is to define a `const` or `constexpr` value and give it a descriptive name. This also makes it easier to reuse the value elsewhere in the code. For these I might call them `UTF16_SURROGATE_START` and `UTF16_SURROGATE_END` or similar.
https://github.com/llvm/llvm-project/pull/230434
More information about the libc-commits
mailing list