diff options
author | Zufu Liu <unknown> | 2018-03-22 15:02:38 +1100 |
---|---|---|
committer | Zufu Liu <unknown> | 2018-03-22 15:02:38 +1100 |
commit | ff707f0fe276677a4d89633ae4964e8b94712ca3 (patch) | |
tree | 103d8741341108a8dc04ef59923e19da6f4a64e4 /win32/PlatWin.cxx | |
parent | 9e4cdff7752304fff978ab7f606b64ea85310baf (diff) | |
download | scintilla-mirror-ff707f0fe276677a4d89633ae4964e8b94712ca3.tar.gz |
Feature [feature-requests:#1211]. Use pre-computed table for UTF8BytesOfLead.
Friendlier treatment of invalid UTF-8.
Add tests for UniConversion handling invalid UTF-8. Simplify UTF8Classify tests.
Diffstat (limited to 'win32/PlatWin.cxx')
-rw-r--r-- | win32/PlatWin.cxx | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 9e89e2f84..79970a969 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -951,12 +951,14 @@ void SurfaceGDI::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION * return; } // Map the widths given for UTF-16 characters back onto the UTF-8 input string + const unsigned char *us = reinterpret_cast<const unsigned char *>(s); for (int ui = 0; ui < fit; ui++) { - const unsigned int lenChar = UTF8BytesOfLead[static_cast<unsigned char>(s[i])]; - if (lenChar == 4) { // Non-BMP + const unsigned char uch = us[i]; + const unsigned int byteCount = UTF8BytesOfLead[uch]; + if (byteCount == 4) { // Non-BMP ui++; } - for (unsigned int bytePos=0; (bytePos<lenChar) && (i<len); bytePos++) { + for (unsigned int bytePos=0; (bytePos<byteCount) && (i<len); bytePos++) { positions[i++] = static_cast<XYPOSITION>(poses.buffer[ui]); } } @@ -1623,16 +1625,11 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION * int i=0; while (ui<tbuf.tlen) { const unsigned char uch = us[i]; - unsigned int lenChar = 1; - if (uch >= (0x80 + 0x40 + 0x20 + 0x10)) { - lenChar = 4; + const unsigned int byteCount = UTF8BytesOfLead[uch]; + if (byteCount == 4) { // Non-BMP ui++; - } else if (uch >= (0x80 + 0x40 + 0x20)) { - lenChar = 3; - } else if (uch >= (0x80)) { - lenChar = 2; } - for (unsigned int bytePos=0; (bytePos<lenChar) && (i<len); bytePos++) { + for (unsigned int bytePos=0; (bytePos<byteCount) && (i<len); bytePos++) { positions[i++] = poses.buffer[ui]; } ui++; |