From 852aaee6cbcf26f09047f4536bc30ce7e34bcf05 Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Thu, 12 Jan 2017 05:00:08 +1300
Subject: [PATCH] MultibyteToWchar: use ucnv_getNextUChar
---
src/system/libroot/add-ons/icu/ICUCtypeData.cpp | 25 +++----------------------
1 file changed, 3 insertions(+), 22 deletions(-)
diff --git a/src/system/libroot/add-ons/icu/ICUCtypeData.cpp b/src/system/libroot/add-ons/icu/ICUCtypeData.cpp
index 3940c80..32c1925 100644
a
|
b
|
ICUCtypeData::MultibyteToWchar(wchar_t* wcOut, const char* mb, size_t mbLen,
|
223 | 223 | UErrorCode icuStatus = U_ZERO_ERROR; |
224 | 224 | |
225 | 225 | const char* buffer = mb; |
226 | | UChar targetBuffer[2]; |
227 | | UChar* target = targetBuffer; |
228 | | ucnv_toUnicode(converter, &target, target + 1, &buffer, buffer + mbLen, |
229 | | NULL, FALSE, &icuStatus); |
230 | | size_t sourceLengthUsed = buffer - mb; |
231 | | size_t targetLengthUsed = (size_t)(target - targetBuffer); |
232 | | |
233 | | if (icuStatus == U_BUFFER_OVERFLOW_ERROR && targetLengthUsed > 0) { |
234 | | // we've got one character, which is all that we wanted |
235 | | icuStatus = U_ZERO_ERROR; |
236 | | } |
| 226 | UChar32 unicodeChar = ucnv_getNextUChar(converter, &buffer, buffer + mbLen, |
| 227 | &icuStatus); |
237 | 228 | |
238 | 229 | if (!U_SUCCESS(icuStatus)) { |
239 | | // conversion failed because of illegal character sequence |
240 | 230 | TRACE(("MultibyteToWchar(): illegal character sequence\n")); |
241 | 231 | ucnv_resetToUnicode(converter); |
242 | 232 | result = B_BAD_DATA; |
243 | | } else if (targetLengthUsed == 0) { |
244 | | TRACE(("MultibyteToWchar(): incomplete character (len=%lu)\n", mbLen)); |
245 | | for (size_t i = 0; i < mbLen; ++i) |
246 | | TRACE(("\tbyte %lu: %x\n", i, mb[i])); |
247 | | mbState->count = sourceLengthUsed; |
248 | | result = B_BAD_INDEX; |
249 | 233 | } else { |
250 | | UChar32 unicodeChar = 0xBADBEEF; |
251 | | U16_GET(targetBuffer, 0, 0, 2, unicodeChar); |
252 | | |
253 | 234 | if (unicodeChar == 0) { |
254 | 235 | // reset to initial state |
255 | 236 | _DropConverterFromMbState(mbState); |
… |
… |
ICUCtypeData::MultibyteToWchar(wchar_t* wcOut, const char* mb, size_t mbLen,
|
257 | 238 | lengthOut = 0; |
258 | 239 | } else { |
259 | 240 | mbState->count = 0; |
260 | | lengthOut = sourceLengthUsed; |
| 241 | lengthOut = buffer - mb; |
261 | 242 | } |
262 | 243 | |
263 | 244 | if (wcOut != NULL) |