sal/rtl/strtmpl.cxx | 32 +++++++++++++++++++++----------- sal/rtl/ustring.cxx | 16 ++++++++++++++-- 2 files changed, 35 insertions(+), 13 deletions(-)
New commits: commit b71c35216c5fb775aa578a0ada0406f6baad8487 Author: Stephan Bergmann <sberg...@redhat.com> Date: Tue Aug 20 22:25:33 2013 +0200 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 c8e39e66528affb66f1ae121fa36dd4ab31a9b0b "Introduce rtl::compareIgnoreCase and deprecate rtl/character.hxx equivalents," which this commit partly reverts. Change-Id: Ib2eed3a1896e83d9c66b0479a03f9ec51e1c4dc0 diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index 8d759b4..dc54945 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -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; diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx index 3f54088..abf9db7 100644 --- a/sal/rtl/ustring.cxx +++ b/sal/rtl/ustring.cxx @@ -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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits