Ticket #13184: 0001-MultibyteToWchar-use-ucnv_getNextUChar.patch

File 0001-MultibyteToWchar-use-ucnv_getNextUChar.patch, 2.2 KB (added by jessicah, 8 years ago)
  • src/system/libroot/add-ons/icu/ICUCtypeData.cpp

    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,  
    223223    UErrorCode icuStatus = U_ZERO_ERROR;
    224224
    225225    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);
    237228
    238229    if (!U_SUCCESS(icuStatus)) {
    239         // conversion failed because of illegal character sequence
    240230        TRACE(("MultibyteToWchar(): illegal character sequence\n"));
    241231        ucnv_resetToUnicode(converter);
    242232        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;
    249233    } else {
    250         UChar32 unicodeChar = 0xBADBEEF;
    251         U16_GET(targetBuffer, 0, 0, 2, unicodeChar);
    252 
    253234        if (unicodeChar == 0) {
    254235            // reset to initial state
    255236            _DropConverterFromMbState(mbState);
    ICUCtypeData::MultibyteToWchar(wchar_t* wcOut, const char* mb, size_t mbLen,  
    257238            lengthOut = 0;
    258239        } else {
    259240            mbState->count = 0;
    260             lengthOut = sourceLengthUsed;
     241            lengthOut = buffer - mb;
    261242        }
    262243
    263244        if (wcOut != NULL)