diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-04-03 22:16:04 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-04-04 10:05:56 +0200 |
commit | 9573cd63698a92c5d7b87725ec239d938f897133 (patch) | |
tree | 0159ff59e39b3a85c03e94d26953c03c3ea40562 /sal | |
parent | bd08874073eab31501eceeda640340bcc97385a2 (diff) |
Fix ASCII-only check
...which did not work e.g. for broken single-byte input 0x80.
Change-Id: I4dff41e4f18dfce376695b438004c2af853cf4fa
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/ustring.cxx | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx index 8c9760c8bb60..f10e755bbc7b 100644 --- a/sal/rtl/ustring.cxx +++ b/sal/rtl/ustring.cxx @@ -551,12 +551,13 @@ void SAL_CALL rtl_uString_newFromCodePoints( /* ======================================================================= */ -static int rtl_ImplGetFastUTF8UnicodeLen( const sal_Char* pStr, sal_Int32 nLen ) +static int rtl_ImplGetFastUTF8UnicodeLen( const sal_Char* pStr, sal_Int32 nLen, bool * ascii ) { int n; unsigned char c; const sal_Char* pEndStr; + *ascii = true; n = 0; pEndStr = pStr+nLen; while ( pStr < pEndStr ) @@ -565,18 +566,22 @@ static int rtl_ImplGetFastUTF8UnicodeLen( const sal_Char* pStr, sal_Int32 nLen ) if ( !(c & 0x80) ) pStr++; - else if ( (c & 0xE0) == 0xC0 ) - pStr += 2; - else if ( (c & 0xF0) == 0xE0 ) - pStr += 3; - else if ( (c & 0xF8) == 0xF0 ) - pStr += 4; - else if ( (c & 0xFC) == 0xF8 ) - pStr += 5; - else if ( (c & 0xFE) == 0xFC ) - pStr += 6; else - pStr++; + { + if ( (c & 0xE0) == 0xC0 ) + pStr += 2; + else if ( (c & 0xF0) == 0xE0 ) + pStr += 3; + else if ( (c & 0xF8) == 0xF0 ) + pStr += 4; + else if ( (c & 0xFC) == 0xF8 ) + pStr += 5; + else if ( (c & 0xFE) == 0xFC ) + pStr += 6; + else + pStr++; + *ascii = false; + } n++; } @@ -652,10 +657,11 @@ static void rtl_string2UString_status( rtl_uString** ppThis, the buffer if needed */ if ( eTextEncoding == RTL_TEXTENCODING_UTF8 ) { - nNewLen = rtl_ImplGetFastUTF8UnicodeLen( pStr, nLen ); + bool ascii; + nNewLen = rtl_ImplGetFastUTF8UnicodeLen( pStr, nLen, &ascii ); /* Includes the string only ASCII, then we could copy the buffer faster */ - if ( nNewLen == (sal_Size)nLen ) + if ( ascii ) { sal_Unicode* pBuffer; *ppThis = rtl_uString_ImplAlloc( nLen ); |