Introduce rtl::compareIgnoreCase and deprecate rtl/character.hxx equivalents.

Change-Id: Id90935fd2b0f904f89477792edc8140cfc31e91f
Reviewed-on: https://gerrit.libreoffice.org/5412
Reviewed-by: Petr Mladek <pmladek@suse.cz>
Tested-by: Petr Mladek <pmladek@suse.cz>
This commit is contained in:
Arnaud Versini 2013-08-10 12:41:03 +02:00 committed by Petr Mladek
parent 2e45813b7e
commit c8e39e6652
6 changed files with 53 additions and 46 deletions

View File

@ -21,8 +21,10 @@
#define INCLUDED_RTL_CHARACTER_HXX #define INCLUDED_RTL_CHARACTER_HXX
#include "sal/config.h" #include "sal/config.h"
#include "sal/types.h" #include "sal/types.h"
#include "sal/log.hxx"
#include <assert.h>
namespace rtl namespace rtl
{ {
@ -137,6 +139,29 @@ inline bool isAsciiHexDigit(sal_uInt32 nUtf32)
return isAsciiCanonicHexDigit(nUtf32) || (nUtf32 >= 'a' && nUtf32 <= 'f'); 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 }//rtl namespace
#endif #endif

View File

@ -16,6 +16,7 @@
* except in compliance with the License. You may obtain a copy of * except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include "unotools/unotoolsdllapi.h" #include "unotools/unotoolsdllapi.h"
#ifndef _UNOTOOLS_CHARCLASS_HXX #ifndef _UNOTOOLS_CHARCLASS_HXX
@ -33,7 +34,6 @@
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <rtl/character.hxx> #include <rtl/character.hxx>
namespace com { namespace sun { namespace star { namespace com { namespace sun { namespace star {
namespace uno { namespace uno {
class XComponentContext; class XComponentContext;
@ -93,18 +93,21 @@ public:
/// isdigit() on ascii values /// isdigit() on ascii values
SAL_DEPRECATED("Use rtl::isAsciiDigit instead")
static inline bool isAsciiDigit( sal_Unicode c ) static inline bool isAsciiDigit( sal_Unicode c )
{ {
return rtl::isAsciiDigit( c ); return rtl::isAsciiDigit( c );
} }
/// isalpha() on ascii values /// isalpha() on ascii values
SAL_DEPRECATED("Use rtl::isAsciiAlpha instead")
static inline bool isAsciiAlpha( sal_Unicode c ) static inline bool isAsciiAlpha( sal_Unicode c )
{ {
return rtl::isAsciiAlpha( c ); return rtl::isAsciiAlpha( c );
} }
/// isalnum() on ascii values /// isalnum() on ascii values
SAL_DEPRECATED("Use rtl::isAsciiAlphanumeric instead")
static inline bool isAsciiAlphaNumeric( sal_Unicode c ) static inline bool isAsciiAlphaNumeric( sal_Unicode c )
{ {
return rtl::isAsciiAlphanumeric( c ); return rtl::isAsciiAlphanumeric( c );

View File

@ -27,6 +27,8 @@
#include <limits> #include <limits>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <rtl/character.hxx>
/* /*
inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest, inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest,
const IMPL_RTL_STRCODE* pSrc, 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_THROW_EXTERN_C()
{ {
sal_Int32 nRet; sal_Int32 nRet;
sal_Int32 c1;
sal_Int32 c2;
do do
{ {
/* If character between 'A' and 'Z', than convert it to lowercase */ nRet = rtl::compareAsciiIgnoreCase(
c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ); (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ),
c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ); (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ));
if ( (c1 >= 65) && (c1 <= 90) )
c1 += 32;
if ( (c2 >= 65) && (c2 <= 90) )
c2 += 32;
nRet = c1-c2;
if ( nRet != 0 ) if ( nRet != 0 )
return nRet; return nRet;
pStr1++; pStr1++;
pStr2++; pStr2++;
} }
while ( c2 ); while ( *pStr2 );
return 0; 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* pStr1End = pStr1 + nStr1Len;
const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
sal_Int32 nRet; sal_Int32 nRet;
sal_Int32 c1;
sal_Int32 c2;
while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) ) while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) )
{ {
/* If character between 'A' and 'Z', than convert it to lowercase */ nRet = rtl::compareAsciiIgnoreCase(
c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ); (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ),
c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ); (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ));
if ( (c1 >= 65) && (c1 <= 90) )
c1 += 32;
if ( (c2 >= 65) && (c2 <= 90) )
c2 += 32;
nRet = c1-c2;
if ( nRet != 0 ) if ( nRet != 0 )
return nRet; return nRet;

View File

@ -41,6 +41,7 @@
#include "strimp.hxx" #include "strimp.hxx"
#include "surrogates.hxx" #include "surrogates.hxx"
#include <rtl/ustring.h> #include <rtl/ustring.h>
#include <rtl/character.hxx>
#include "rtl/math.h" #include "rtl/math.h"
#include "rtl/tencinfo.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; const sal_Unicode* pStr1End = pStr1 + nStr1Len;
sal_Int32 nRet; sal_Int32 nRet;
sal_Int32 c1;
sal_Int32 c2;
while ( (nShortenedLength > 0) && while ( (nShortenedLength > 0) &&
(pStr1 < pStr1End) && *pStr2 ) (pStr1 < pStr1End) && *pStr2 )
{ {
/* Check ASCII range */ nRet = rtl::compareAsciiIgnoreCase( *pStr1, (sal_Int32)((unsigned char)*pStr2));
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;
if ( nRet != 0 ) if ( nRet != 0 )
return nRet; return nRet;

View File

@ -125,7 +125,7 @@ void lcl_getSingleCellAddressFromXMLString(
sal_Int32 i = nLength - 1, nColumn = 0; sal_Int32 i = nLength - 1, nColumn = 0;
// parse number for row // parse number for row
while( CharClass::isAsciiDigit( pStrArray[ i ] ) && i >= 0 ) while( rtl::isAsciiDigit( pStrArray[ i ] ) && i >= 0 )
i--; i--;
rOutCell.nRow = (aCellStr.copy( i + 1 )).toInt32() - 1; rOutCell.nRow = (aCellStr.copy( i + 1 )).toInt32() - 1;
// a dollar in XML means absolute (whereas in UI it means relative) // a dollar in XML means absolute (whereas in UI it means relative)
@ -139,7 +139,7 @@ void lcl_getSingleCellAddressFromXMLString(
// parse rest for column // parse rest for column
sal_Int32 nPower = 1; sal_Int32 nPower = 1;
while( CharClass::isAsciiAlpha( pStrArray[ i ] )) while( rtl::isAsciiAlpha( pStrArray[ i ] ))
{ {
nColumn += (pStrArray[ i ] - aLetterA + 1) * nPower; nColumn += (pStrArray[ i ] - aLetterA + 1) * nPower;
i--; i--;

View File

@ -20,6 +20,7 @@
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <unotools/charclass.hxx> #include <unotools/charclass.hxx>
#include <rtl/character.hxx>
#include <tools/debug.hxx> #include <tools/debug.hxx>
#include <com/sun/star/i18n/CharacterClassification.hpp> #include <com/sun/star/i18n/CharacterClassification.hpp>
@ -85,7 +86,7 @@ bool CharClass::isAsciiNumeric( const OUString& rStr )
do do
{ {
if ( !isAsciiDigit( *p ) ) if ( !rtl::isAsciiDigit( *p ) )
return false; return false;
} }
while ( ++p < pStop ); while ( ++p < pStop );
@ -104,7 +105,7 @@ bool CharClass::isAsciiAlpha( const OUString& rStr )
do do
{ {
if ( !isAsciiAlpha( *p ) ) if ( !rtl::isAsciiAlpha( *p ) )
return false; return false;
} }
while ( ++p < pStop ); while ( ++p < pStop );
@ -118,7 +119,7 @@ bool CharClass::isAlpha( const OUString& rStr, sal_Int32 nPos ) const
{ {
sal_Unicode c = rStr[nPos]; sal_Unicode c = rStr[nPos];
if ( c < 128 ) if ( c < 128 )
return isAsciiAlpha( c ); return rtl::isAsciiAlpha( c );
try try
{ {
@ -141,7 +142,7 @@ bool CharClass::isLetter( const OUString& rStr, sal_Int32 nPos ) const
{ {
sal_Unicode c = rStr[nPos]; sal_Unicode c = rStr[nPos];
if ( c < 128 ) if ( c < 128 )
return isAsciiAlpha( c ); return rtl::isAsciiAlpha( c );
try try
{ {
@ -180,7 +181,7 @@ bool CharClass::isDigit( const OUString& rStr, sal_Int32 nPos ) const
{ {
sal_Unicode c = rStr[ nPos ]; sal_Unicode c = rStr[ nPos ];
if ( c < 128 ) if ( c < 128 )
return isAsciiDigit( c ); return rtl::isAsciiDigit( c );
try try
{ {
@ -219,7 +220,7 @@ bool CharClass::isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const
{ {
sal_Unicode c = rStr[nPos]; sal_Unicode c = rStr[nPos];
if ( c < 128 ) if ( c < 128 )
return isAsciiAlphaNumeric( c ); return rtl::isAsciiAlphanumeric( c );
try try
{ {
@ -241,7 +242,7 @@ bool CharClass::isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const
{ {
sal_Unicode c = rStr[nPos]; sal_Unicode c = rStr[nPos];
if ( c < 128 ) if ( c < 128 )
return isAsciiAlphaNumeric( c ); return rtl::isAsciiAlphanumeric( c );
try try
{ {