Kaydet (Commit) b71c3521 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

rtl::compareAsciiIgnoreCase cannot be used here

...as its assert requires that both input characters are ASCII, which need not
be the case in these compareIgnoreAsciiCase functions.  (Even if they take one
literal argument that must be strictly ASCII, the other argument can be an
arbitrary Unicode string in the case of OUString or an arbitrary 8-bit string in
the case of OString).

The logically correct version of rtl::compareAsciiIgnoreCase would arguably be
one that requires its two arguments to be valid UTF-32 code units, but that
could not be used in these places either, as for OUString they operate on
individual UTF-16 code units.

rtl::compareAsciiIgnoreCase likely makes less sense after all than assumed in
c8e39e66 "Introduce rtl::compareIgnoreCase and
deprecate rtl/character.hxx equivalents," which this commit partly reverts.

Change-Id: Ib2eed3a1896e83d9c66b0479a03f9ec51e1c4dc0
üst f193e731
......@@ -27,8 +27,6 @@
#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,
......@@ -172,19 +170,25 @@ 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
{
nRet = rtl::compareAsciiIgnoreCase(
(sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ),
(sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ));
/* 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;
if ( nRet != 0 )
return nRet;
pStr1++;
pStr2++;
}
while ( *pStr2 );
while ( c2 );
return 0;
}
......@@ -200,12 +204,18 @@ 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) )
{
nRet = rtl::compareAsciiIgnoreCase(
(sal_Int32)IMPL_RTL_USTRCODE( *pStr1 ),
(sal_Int32)IMPL_RTL_USTRCODE( *pStr2 ));
/* 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;
if ( nRet != 0 )
return nRet;
......
......@@ -41,7 +41,6 @@
#include "strimp.hxx"
#include "surrogates.hxx"
#include <rtl/ustring.h>
#include <rtl/character.hxx>
#include "rtl/math.h"
#include "rtl/tencinfo.h"
......@@ -405,10 +404,23 @@ 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 )
{
nRet = rtl::compareAsciiIgnoreCase( *pStr1, (sal_Int32)((unsigned char)*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;
if ( nRet != 0 )
return nRet;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment