diff options
-rw-r--r-- | include/rtl/character.hxx | 27 | ||||
-rw-r--r-- | include/unotools/charclass.hxx | 5 | ||||
-rw-r--r-- | sal/rtl/strtmpl.cxx | 32 | ||||
-rw-r--r-- | sal/rtl/ustring.cxx | 16 | ||||
-rw-r--r-- | sw/source/core/unocore/XMLRangeHelper.cxx | 4 | ||||
-rw-r--r-- | unotools/source/i18n/charclass.cxx | 15 |
6 files changed, 53 insertions, 46 deletions
diff --git a/include/rtl/character.hxx b/include/rtl/character.hxx index 0ba86d6c065b..01350e19ee78 100644 --- a/include/rtl/character.hxx +++ b/include/rtl/character.hxx @@ -21,8 +21,10 @@ #define INCLUDED_RTL_CHARACTER_HXX #include "sal/config.h" - #include "sal/types.h" +#include "sal/log.hxx" + +#include <assert.h> namespace rtl { @@ -137,6 +139,29 @@ inline bool isAsciiHexDigit(sal_uInt32 nUtf32) return isAsciiCanonicHexDigit(nUtf32) || (nUtf32 >= 'a' && nUtf32 <= 'f'); } +/** Compare two US-ASCII characters. + + @param nChar1 A Unicode scalar value (represented as a UTF-32 code unit). + @param nChar2 A unicode scalar value (represented as a UTF-32 code unit). + + @return + 0 if both strings are equal + < 0 - if this string is less than the string argument + > 0 - if this string is greater than the string argument + + @since LibreOffice 4.2 + */ +inline sal_Int32 compareAsciiIgnoreCase(sal_uInt32 nChar1, sal_uInt32 nChar2) +{ + assert(isAscii(nChar1) && isAscii(nChar2)); + if ( isAsciiUpperCase(nChar1) ) + nChar1 += 32; + if ( isAsciiUpperCase(nChar2) ) + nChar2 += 32; + return nChar1 - nChar2; +} + + }//rtl namespace #endif diff --git a/include/unotools/charclass.hxx b/include/unotools/charclass.hxx index 1eb2954a0491..0522df360ce2 100644 --- a/include/unotools/charclass.hxx +++ b/include/unotools/charclass.hxx @@ -16,6 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ + #include "unotools/unotoolsdllapi.h" #ifndef _UNOTOOLS_CHARCLASS_HXX @@ -33,7 +34,6 @@ #include <osl/mutex.hxx> #include <rtl/character.hxx> - namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; @@ -93,18 +93,21 @@ public: /// isdigit() on ascii values + SAL_DEPRECATED("Use rtl::isAsciiDigit instead") static inline bool isAsciiDigit( sal_Unicode c ) { return rtl::isAsciiDigit( c ); } /// isalpha() on ascii values + SAL_DEPRECATED("Use rtl::isAsciiAlpha instead") static inline bool isAsciiAlpha( sal_Unicode c ) { return rtl::isAsciiAlpha( c ); } /// isalnum() on ascii values + SAL_DEPRECATED("Use rtl::isAsciiAlphanumeric instead") static inline bool isAsciiAlphaNumeric( sal_Unicode c ) { return rtl::isAsciiAlphanumeric( c ); diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index dc54945ab6a9..8d759b4c7826 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -27,6 +27,8 @@ #include <limits> #include <boost/static_assert.hpp> +#include <rtl/character.hxx> + /* inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest, const IMPL_RTL_STRCODE* pSrc, @@ -170,25 +172,19 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase )( const IMPL_RTL_ST SAL_THROW_EXTERN_C() { sal_Int32 nRet; - sal_Int32 c1; - sal_Int32 c2; do { - /* 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; + nRet = rtl::compareAsciiIgnoreCase( + (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ), + (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 )); + if ( nRet != 0 ) return nRet; pStr1++; pStr2++; } - while ( c2 ); + while ( *pStr2 ); return 0; } @@ -204,18 +200,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; 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; + nRet = rtl::compareAsciiIgnoreCase( + (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ), + (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 )); + if ( nRet != 0 ) return nRet; diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx index abf9db7b388b..3f54088c8573 100644 --- a/sal/rtl/ustring.cxx +++ b/sal/rtl/ustring.cxx @@ -41,6 +41,7 @@ #include "strimp.hxx" #include "surrogates.hxx" #include <rtl/ustring.h> +#include <rtl/character.hxx> #include "rtl/math.h" #include "rtl/tencinfo.h" @@ -404,23 +405,10 @@ sal_Int32 SAL_CALL rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( co { const sal_Unicode* pStr1End = pStr1 + nStr1Len; sal_Int32 nRet; - sal_Int32 c1; - sal_Int32 c2; while ( (nShortenedLength > 0) && (pStr1 < pStr1End) && *pStr2 ) { - /* Check ASCII range */ - SAL_WARN_IF( ((unsigned char)*pStr2) > 127, "rtl.string", - "rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength - Found char > 127" ); - - /* If character between 'A' and 'Z', than convert it to lowercase */ - c1 = (sal_Int32)*pStr1; - c2 = (sal_Int32)((unsigned char)*pStr2); - if ( (c1 >= 65) && (c1 <= 90) ) - c1 += 32; - if ( (c2 >= 65) && (c2 <= 90) ) - c2 += 32; - nRet = c1-c2; + nRet = rtl::compareAsciiIgnoreCase( *pStr1, (sal_Int32)((unsigned char)*pStr2)); if ( nRet != 0 ) return nRet; diff --git a/sw/source/core/unocore/XMLRangeHelper.cxx b/sw/source/core/unocore/XMLRangeHelper.cxx index 471a0c3cc583..372074866fe0 100644 --- a/sw/source/core/unocore/XMLRangeHelper.cxx +++ b/sw/source/core/unocore/XMLRangeHelper.cxx @@ -125,7 +125,7 @@ void lcl_getSingleCellAddressFromXMLString( sal_Int32 i = nLength - 1, nColumn = 0; // parse number for row - while( CharClass::isAsciiDigit( pStrArray[ i ] ) && i >= 0 ) + while( rtl::isAsciiDigit( pStrArray[ i ] ) && i >= 0 ) i--; rOutCell.nRow = (aCellStr.copy( i + 1 )).toInt32() - 1; // a dollar in XML means absolute (whereas in UI it means relative) @@ -139,7 +139,7 @@ void lcl_getSingleCellAddressFromXMLString( // parse rest for column sal_Int32 nPower = 1; - while( CharClass::isAsciiAlpha( pStrArray[ i ] )) + while( rtl::isAsciiAlpha( pStrArray[ i ] )) { nColumn += (pStrArray[ i ] - aLetterA + 1) * nPower; i--; diff --git a/unotools/source/i18n/charclass.cxx b/unotools/source/i18n/charclass.cxx index 2b620262030c..ba86a2b531fc 100644 --- a/unotools/source/i18n/charclass.cxx +++ b/unotools/source/i18n/charclass.cxx @@ -20,6 +20,7 @@ #include <comphelper/processfactory.hxx> #include <unotools/charclass.hxx> +#include <rtl/character.hxx> #include <tools/debug.hxx> #include <com/sun/star/i18n/CharacterClassification.hpp> @@ -85,7 +86,7 @@ bool CharClass::isAsciiNumeric( const OUString& rStr ) do { - if ( !isAsciiDigit( *p ) ) + if ( !rtl::isAsciiDigit( *p ) ) return false; } while ( ++p < pStop ); @@ -104,7 +105,7 @@ bool CharClass::isAsciiAlpha( const OUString& rStr ) do { - if ( !isAsciiAlpha( *p ) ) + if ( !rtl::isAsciiAlpha( *p ) ) return false; } while ( ++p < pStop ); @@ -118,7 +119,7 @@ bool CharClass::isAlpha( const OUString& rStr, sal_Int32 nPos ) const { sal_Unicode c = rStr[nPos]; if ( c < 128 ) - return isAsciiAlpha( c ); + return rtl::isAsciiAlpha( c ); try { @@ -141,7 +142,7 @@ bool CharClass::isLetter( const OUString& rStr, sal_Int32 nPos ) const { sal_Unicode c = rStr[nPos]; if ( c < 128 ) - return isAsciiAlpha( c ); + return rtl::isAsciiAlpha( c ); try { @@ -180,7 +181,7 @@ bool CharClass::isDigit( const OUString& rStr, sal_Int32 nPos ) const { sal_Unicode c = rStr[ nPos ]; if ( c < 128 ) - return isAsciiDigit( c ); + return rtl::isAsciiDigit( c ); try { @@ -219,7 +220,7 @@ bool CharClass::isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const { sal_Unicode c = rStr[nPos]; if ( c < 128 ) - return isAsciiAlphaNumeric( c ); + return rtl::isAsciiAlphanumeric( c ); try { @@ -241,7 +242,7 @@ bool CharClass::isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const { sal_Unicode c = rStr[nPos]; if ( c < 128 ) - return isAsciiAlphaNumeric( c ); + return rtl::isAsciiAlphanumeric( c ); try { |