diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-08-20 22:25:33 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-08-20 22:34:12 +0200 |
commit | b71c35216c5fb775aa578a0ada0406f6baad8487 (patch) | |
tree | 6bfa98ea34da553c0306db105661a45a8cd628bb /sal/rtl/ustring.cxx | |
parent | f193e73136e5808b998339054e2278b1b2d16637 (diff) |
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
Diffstat (limited to 'sal/rtl/ustring.cxx')
-rw-r--r-- | sal/rtl/ustring.cxx | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx index 3f54088c8573..abf9db7b388b 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; |