diff options
author | Zufu Liu <unknown> | 2018-03-24 13:53:22 +1100 |
---|---|---|
committer | Zufu Liu <unknown> | 2018-03-24 13:53:22 +1100 |
commit | 0bb4d5456748c8794a943b4716ee089d0590519c (patch) | |
tree | d3a1f8654824ca8f6e9892cb0ae9b8ce172efed4 /src/UniConversion.h | |
parent | f3830c19917c254dcddfd272518a7b749fe89129 (diff) | |
download | scintilla-mirror-0bb4d5456748c8794a943b4716ee089d0590519c.tar.gz |
Feature [feature-requests:#1212]. Move Unicode conversions into UniConversion.
Move Unicode conversion functions UnicodeFromUTF8 and UTF8FromUTF32Character
into UniConversion.
Diffstat (limited to 'src/UniConversion.h')
-rw-r--r-- | src/UniConversion.h | 16 |
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; } } |