diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-12 20:53:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-12 20:53:03 -0700 |
| commit | b390566b55700582321b09b72c726b8dff9bd819 (patch) | |
| tree | a2fd8e50fcbde29dd2651e08a78021f2ae9d72de /source/core/slang-char-encode.cpp | |
| parent | 20bd48659d0009de5477380c335e2419f4c66f8b (diff) | |
Support unicode identifier names. (#4772)
* Support unicode identifier names.
* Fix.
* Fix language server.
* Fix build errors.
* Fix.
* Fix offset translation in language server.
Diffstat (limited to 'source/core/slang-char-encode.cpp')
| -rw-r--r-- | source/core/slang-char-encode.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
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 |
