aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/UniConversion.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/UniConversion.cxx')
-rw-r--r--src/UniConversion.cxx58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/UniConversion.cxx b/src/UniConversion.cxx
index a695b0f3c..44eceeda6 100644
--- a/src/UniConversion.cxx
+++ b/src/UniConversion.cxx
@@ -17,7 +17,7 @@ using namespace Scintilla;
namespace Scintilla {
-size_t UTF8Length(std::wstring_view wsv) {
+size_t UTF8Length(std::wstring_view wsv) noexcept {
size_t len = 0;
for (size_t i = 0; i < wsv.length() && wsv[i];) {
const unsigned int uch = wsv[i];
@@ -78,7 +78,7 @@ void UTF8FromUTF16(std::wstring_view wsv, char *putf, size_t len) {
putf[k] = '\0';
}
-void UTF8FromUTF32Character(int uch, char *putf) {
+void UTF8FromUTF32Character(int uch, char *putf) noexcept {
size_t k = 0;
if (uch < 0x80) {
putf[k++] = static_cast<char>(uch);
@@ -98,14 +98,14 @@ void UTF8FromUTF32Character(int uch, char *putf) {
putf[k] = '\0';
}
-size_t UTF16Length(std::string_view sv) {
+size_t UTF16Length(std::string_view svu8) noexcept {
size_t ulen = 0;
- for (size_t i = 0; i<sv.length();) {
- const unsigned char ch = sv[i];
+ for (size_t i = 0; i< svu8.length();) {
+ const unsigned char ch = svu8[i];
const unsigned int byteCount = UTF8BytesOfLead[ch];
const unsigned int utf16Len = UTF16LengthFromUTF8ByteCount(byteCount);
i += byteCount;
- ulen += (i > sv.length()) ? 1 : utf16Len;
+ ulen += (i > svu8.length()) ? 1 : utf16Len;
}
return ulen;
}
@@ -116,14 +116,14 @@ constexpr unsigned char TrailByteValue(unsigned char c) {
return c & 0b0011'1111;
}
-size_t UTF16FromUTF8(std::string_view sv, wchar_t *tbuf, size_t tlen) {
+size_t UTF16FromUTF8(std::string_view svu8, wchar_t *tbuf, size_t tlen) {
size_t ui = 0;
- for (size_t i = 0; i < sv.length();) {
- unsigned char ch = sv[i];
+ for (size_t i = 0; i < svu8.length();) {
+ unsigned char ch = svu8[i];
const unsigned int byteCount = UTF8BytesOfLead[ch];
unsigned int value;
- if (i + byteCount > sv.length()) {
+ if (i + byteCount > svu8.length()) {
// Trying to read past end but still have space to write
if (ui < tlen) {
tbuf[ui] = ch;
@@ -144,26 +144,26 @@ size_t UTF16FromUTF8(std::string_view sv, wchar_t *tbuf, size_t tlen) {
break;
case 2:
value = (ch & 0x1F) << 6;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch);
tbuf[ui] = static_cast<wchar_t>(value);
break;
case 3:
value = (ch & 0xF) << 12;
- ch = sv[i++];
+ ch = svu8[i++];
value += (TrailByteValue(ch) << 6);
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch);
tbuf[ui] = static_cast<wchar_t>(value);
break;
default:
// Outside the BMP so need two surrogates
value = (ch & 0x7) << 18;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch) << 12;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch) << 6;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch);
tbuf[ui] = static_cast<wchar_t>(((value - 0x10000) >> 10) + SURROGATE_LEAD_FIRST);
ui++;
@@ -186,14 +186,14 @@ size_t UTF32Length(std::string_view svu8) noexcept {
return ulen;
}
-size_t UTF32FromUTF8(std::string_view sv, unsigned int *tbuf, size_t tlen) {
+size_t UTF32FromUTF8(std::string_view svu8, unsigned int *tbuf, size_t tlen) {
size_t ui = 0;
- for (size_t i = 0; i < sv.length();) {
- unsigned char ch = sv[i];
+ for (size_t i = 0; i < svu8.length();) {
+ unsigned char ch = svu8[i];
const unsigned int byteCount = UTF8BytesOfLead[ch];
unsigned int value;
- if (i + byteCount > sv.length()) {
+ if (i + byteCount > svu8.length()) {
// Trying to read past end but still have space to write
if (ui < tlen) {
tbuf[ui] = ch;
@@ -213,23 +213,23 @@ size_t UTF32FromUTF8(std::string_view sv, unsigned int *tbuf, size_t tlen) {
break;
case 2:
value = (ch & 0x1F) << 6;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch);
break;
case 3:
value = (ch & 0xF) << 12;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch) << 6;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch);
break;
default:
value = (ch & 0x7) << 18;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch) << 12;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch) << 6;
- ch = sv[i++];
+ ch = svu8[i++];
value += TrailByteValue(ch);
break;
}
@@ -365,9 +365,9 @@ int UTF8DrawBytes(const unsigned char *us, int len) noexcept {
return (utf8StatusNext & UTF8MaskInvalid) ? 1 : (utf8StatusNext & UTF8MaskWidth);
}
-bool UTF8IsValid(std::string_view sv) noexcept {
- const unsigned char *us = reinterpret_cast<const unsigned char *>(sv.data());
- size_t remaining = sv.length();
+bool UTF8IsValid(std::string_view svu8) noexcept {
+ const unsigned char *us = reinterpret_cast<const unsigned char *>(svu8.data());
+ size_t remaining = svu8.length();
while (remaining > 0) {
const int utf8Status = UTF8Classify(us, remaining);
if (utf8Status & UTF8MaskInvalid) {