summaryrefslogtreecommitdiffstats
path: root/source/core/slang-char-encode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-char-encode.cpp')
-rw-r--r--source/core/slang-char-encode.cpp23
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