aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/UniConversion.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-02-04 09:49:10 +1100
committerNeil <nyamatongwe@gmail.com>2025-02-04 09:49:10 +1100
commitef961772c3ced424f034c2055263d7231eccee01 (patch)
treedd6d87ad09d3c474ccc93c57598e20e302ed1599 /src/UniConversion.cxx
parentf54fd2019dd648b29a80ec7429833ab546d3a428 (diff)
downloadscintilla-mirror-ef961772c3ced424f034c2055263d7231eccee01.tar.gz
Add overload of UnicodeFromUTF8 that takes a string_view.
Diffstat (limited to 'src/UniConversion.cxx')
-rw-r--r--src/UniConversion.cxx12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/UniConversion.cxx b/src/UniConversion.cxx
index eadac8915..868fbacf5 100644
--- a/src/UniConversion.cxx
+++ b/src/UniConversion.cxx
@@ -261,6 +261,18 @@ unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept {
return 2;
}
+int UnicodeFromUTF8(std::string_view sv) noexcept {
+ if (!sv.empty()) {
+ const unsigned char uch = sv.front();
+ const unsigned int byteCount = UTF8BytesOfLead[uch];
+ if (sv.length() >= byteCount) {
+ return UnicodeFromUTF8(reinterpret_cast<const unsigned char *>(sv.data()));
+ }
+ }
+ // Failure so let the caller know
+ return unicodeReplacementChar;
+}
+
const unsigned char UTF8BytesOfLead[256] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 00 - 0F
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10 - 1F