diff options
author | Arnaud Versini <arnaud.versini@libreoffice.org> | 2013-09-07 17:11:44 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-09-30 11:49:22 +0200 |
commit | 89de6ba4c65c8709e32fe636ff743d914cf56225 (patch) | |
tree | e74c324223f4a8e9550fe778893a7e98a82490c7 /sal/rtl | |
parent | c1df0ce01b441ffa3e6238d93e49532620a1fc93 (diff) |
Introduce ASCII case conversion and use more/rtl/character.hxx.
Also remove all others implementations.
Change-Id: I1dc108a9103f087bd8ce591dff2ac5dd254746f8
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal/rtl')
-rw-r--r-- | sal/rtl/strtmpl.cxx | 69 |
1 files changed, 19 insertions, 50 deletions
diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index 496216f1c86f..48bf05e65e15 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -27,6 +27,7 @@ #include <string.h> #include <sal/log.hxx> +#include <rtl/character.hxx> #include <boost/static_assert.hpp> /* @@ -179,10 +180,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase )( const IMPL_RTL_ST /* If character between 'A' and 'Z', than convert it to lowercase */ c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ); c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ); - if ( (c1 >= 65) && (c1 <= 90) ) - c1 += 32; - if ( (c2 >= 65) && (c2 <= 90) ) - c2 += 32; + c1 = rtl::toAsciiLowerCase( c1 ); + c2 = rtl::toAsciiLowerCase( c2 ); nRet = c1-c2; if ( nRet != 0 ) return nRet; @@ -205,19 +204,12 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase_WithLength )( const { const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; - sal_Int32 nRet; - sal_Int32 c1; - sal_Int32 c2; + sal_Int32 nRet; while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) ) { - /* If character between 'A' and 'Z', than convert it to lowercase */ - c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ); - c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ); - if ( (c1 >= 65) && (c1 <= 90) ) - c1 += 32; - if ( (c2 >= 65) && (c2 <= 90) ) - c2 += 32; - nRet = c1-c2; + sal_uInt32 c1 = IMPL_RTL_USTRCODE( *pStr1 ); + sal_uInt32 c2 = IMPL_RTL_USTRCODE( *pStr2 ); + nRet = rtl::compareAsciiIgnoreCase(c1, c2); if ( nRet != 0 ) return nRet; @@ -239,20 +231,13 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompareIgnoreAsciiCase_WithLength { const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; - sal_Int32 nRet; - sal_Int32 c1; - sal_Int32 c2; + sal_Int32 nRet; while ( (nShortenedLength > 0) && (pStr1 < pStr1End) && (pStr2 < pStr2End) ) { - /* If character between 'A' and 'Z', than convert it to lowercase */ - c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ); - c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ); - if ( (c1 >= 65) && (c1 <= 90) ) - c1 += 32; - if ( (c2 >= 65) && (c2 <= 90) ) - c2 += 32; - nRet = c1-c2; + sal_uInt32 c1 = IMPL_RTL_USTRCODE( *pStr1 ); + sal_uInt32 c2 = IMPL_RTL_USTRCODE( *pStr2 ); + nRet = rtl::compareAsciiIgnoreCase(c1, c2); if ( nRet != 0 ) return nRet; @@ -577,9 +562,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase )( IMPL_RTL_STRCODE* pStr ) { while ( *pStr ) { - /* Between A-Z (65-90), than to lowercase (+32) */ - if ( (*pStr >= 65) && (*pStr <= 90) ) - *pStr += 32; + *pStr = rtl::toAsciiLowerCase( *pStr ); pStr++; } @@ -593,9 +576,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength )( IMPL_RTL_STRCODE* { while ( nLen > 0 ) { - /* Between A-Z (65-90), than to lowercase (+32) */ - if ( (*pStr >= 65) && (*pStr <= 90) ) - *pStr += 32; + *pStr = rtl::toAsciiLowerCase( *pStr ); pStr++; nLen--; @@ -609,9 +590,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase )( IMPL_RTL_STRCODE* pStr ) { while ( *pStr ) { - /* Between a-z (97-122), than to uppercase (-32) */ - if ( (*pStr >= 97) && (*pStr <= 122) ) - *pStr -= 32; + *pStr = rtl::toAsciiUpperCase( *pStr ); pStr++; } @@ -625,9 +604,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase_WithLength )( IMPL_RTL_STRCODE* { while ( nLen > 0 ) { - /* Between a-z (97-122), than to uppercase (-32) */ - if ( (*pStr >= 97) && (*pStr <= 122) ) - *pStr -= 32; + *pStr = rtl::toAsciiUpperCase( *pStr ); pStr++; nLen--; @@ -1592,7 +1569,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA** while ( nLen > 0 ) { /* Between A-Z (65-90), than to lowercase (+32) */ - if ( (*pCharStr >= 65) && (*pCharStr <= 90) ) + if ( rtl::isAsciiUpperCase(*pCharStr) ) { /* Copy String */ IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer ); @@ -1608,11 +1585,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA** while ( nLen > 0 ) { - /* Between A-Z (65-90), than to lowercase (+32) */ - if ( (*pCharStr >= 65) && (*pCharStr <= 90) ) - *pNewCharStr = *pCharStr+32; - else - *pNewCharStr = *pCharStr; + *pNewCharStr = rtl::toAsciiLowerCase( *pCharStr ); pNewCharStr++; pCharStr++; @@ -1654,7 +1627,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA** while ( nLen > 0 ) { /* Between a-z (97-122), than to uppercase (-32) */ - if ( (*pCharStr >= 97) && (*pCharStr <= 122) ) + if ( rtl::isAsciiLowerCase(*pCharStr) ) { /* Copy String */ IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer ); @@ -1670,11 +1643,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA** while ( nLen > 0 ) { - /* Between a-z (97-122), than to uppercase (-32) */ - if ( (*pCharStr >= 97) && (*pCharStr <= 122) ) - *pNewCharStr = *pCharStr-32; - else - *pNewCharStr = *pCharStr; + *pNewCharStr = rtl::toAsciiUpperCase( *pCharStr ); pNewCharStr++; pCharStr++; |