aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/UniConversion.h
diff options
context:
space:
mode:
authormitchell <unknown>2018-05-05 12:08:22 -0400
committermitchell <unknown>2018-05-05 12:08:22 -0400
commitad5951840a7e9d19c3652151e57466fa2c94e6a7 (patch)
treea77144132bd8fe505c8e0340e1e4e7d66d44bf07 /src/UniConversion.h
parent93462d87c3c8f398d5900be84349f29cb088d849 (diff)
downloadscintilla-mirror-ad5951840a7e9d19c3652151e57466fa2c94e6a7.tar.gz
Backport: Feature [feature-requests:#1212]. Move Unicode conversions into UniConversion.
Move Unicode conversion functions UnicodeFromUTF8 and UTF8FromUTF32Character into UniConversion. Backport of changeset 6645:463fa6965d9a.
Diffstat (limited to 'src/UniConversion.h')
-rw-r--r--src/UniConversion.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/UniConversion.h b/src/UniConversion.h
index 0f22c06e6..98bcd0329 100644
--- a/src/UniConversion.h
+++ b/src/UniConversion.h
@@ -16,6 +16,7 @@ const int unicodeReplacementChar = 0xFFFD;
size_t UTF8Length(const wchar_t *uptr, size_t tlen);
void UTF8FromUTF16(const wchar_t *uptr, size_t tlen, char *putf, size_t len);
+void UTF8FromUTF32Character(int uch, char *putf);
size_t UTF16Length(const char *s, size_t len);
size_t UTF16FromUTF8(const char *s, size_t len, wchar_t *tbuf, size_t tlen);
size_t UTF32FromUTF8(const char *s, size_t len, unsigned int *tbuf, size_t tlen);
@@ -24,6 +25,19 @@ std::string FixInvalidUTF8(const std::string &text);
extern const unsigned char UTF8BytesOfLead[256];
+inline int UnicodeFromUTF8(const unsigned char *us) {
+ switch (UTF8BytesOfLead[us[0]]) {
+ case 1:
+ return us[0];
+ case 2:
+ return ((us[0] & 0x1F) << 6) + (us[1] & 0x3F);
+ case 3:
+ return ((us[0] & 0xF) << 12) + ((us[1] & 0x3F) << 6) + (us[2] & 0x3F);
+ default:
+ return ((us[0] & 0x7) << 18) + ((us[1] & 0x3F) << 12) + ((us[2] & 0x3F) << 6) + (us[3] & 0x3F);
+ }
+}
+
inline bool UTF8IsTrailByte(unsigned char ch) {
return (ch >= 0x80) && (ch < 0xc0);
}
@@ -63,7 +77,7 @@ inline unsigned int UTF16CharLength(wchar_t uch) {
}
inline unsigned int UTF16LengthFromUTF8ByteCount(unsigned int byteCount) {
- return (byteCount < 4) ? 1 : 2;
+ return (byteCount < 4) ? 1 : 2;
}
}