From b390566b55700582321b09b72c726b8dff9bd819 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 12 Aug 2024 20:53:03 -0700 Subject: Support unicode identifier names. (#4772) * Support unicode identifier names. * Fix. * Fix language server. * Fix build errors. * Fix. * Fix offset translation in language server. --- source/core/slang-char-encode.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'source/core/slang-char-encode.cpp') diff --git a/source/core/slang-char-encode.cpp b/source/core/slang-char-encode.cpp index 105cfac7f..526c6c923 100644 --- a/source/core/slang-char-encode.cpp +++ b/source/core/slang-char-encode.cpp @@ -211,4 +211,27 @@ CharEncoding* CharEncoding::UTF32 = &_utf32Encoding; return count; } +Index UTF8Util::calcUTF16CharCount(const UnownedStringSlice& in) +{ + Index count = 0; + Index readPtr = 0; + for (;;) + { + int c = getUnicodePointFromUTF8([&]() -> Byte + { + if (readPtr < in.getLength()) + return in[readPtr++]; + else + return 0; + }); + if (c == 0) + break; + Char16 buffer[2]; + count += encodeUnicodePointToUTF16(c, buffer); + if (readPtr >= in.getLength()) + break; + } + return count; +} + } // namespace Slang -- cgit v1.2.3