Kaydet (Commit) 89de6ba4 authored tarafından Arnaud Versini's avatar Arnaud Versini Kaydeden (comit) Stephan Bergmann

Introduce ASCII case conversion and use more/rtl/character.hxx.

Also remove all others implementations.

Change-Id: I1dc108a9103f087bd8ce591dff2ac5dd254746f8
Signed-off-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst c1df0ce0
......@@ -139,6 +139,40 @@ inline bool isAsciiHexDigit(sal_uInt32 nUtf32)
return isAsciiCanonicHexDigit(nUtf32) || (nUtf32 >= 'a' && nUtf32 <= 'f');
}
/** Convert a character, if ASCII, to upper case.
@param nChar A Unicode scalar value (represented as a UTF-32 code unit).
@return
nChar converted to ASCII upper case
@since LibreOffice 4.2
*/
inline sal_uInt32 toAsciiUpperCase(sal_uInt32 nChar)
{
if( isAsciiLowerCase(nChar) )
nChar -= 32;
return nChar;
}
/** Convert a character, if ASCII, to lower case.
@param nChar A Unicode scalar value (represented as a UTF-32 code unit).
@return
nChar converted to ASCII lower case
@since LibreOffice 4.2
*/
inline sal_uInt32 toAsciiLowerCase(sal_uInt32 nChar)
{
if( isAsciiUpperCase(nChar) )
nChar += 32;
return nChar;
}
/** Compare two US-ASCII characters.
@param nChar1 A Unicode scalar value (represented as a UTF-32 code unit).
......@@ -146,21 +180,18 @@ inline bool isAsciiHexDigit(sal_uInt32 nUtf32)
@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
< 0 - if this nChar1 is less than nChar2 argument
> 0 - if this nChar1 is greater than the nChar2 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;
}
nChar1 = toAsciiLowerCase(nChar1);
nChar2 = toAsciiLowerCase(nChar2);
return ((sal_Int32) nChar1) - ((sal_Int32) nChar2);
}
}//rtl namespace
......
......@@ -137,14 +137,6 @@ public:
HEADER_FIELD_ADDRESS
};
/** Check for US-ASCII character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII character (0x00--0x7F).
*/
static inline bool isUSASCII(sal_uInt32 nChar);
/** Check for ISO 8859-1 character.
@param nChar Some UCS-4 character.
......@@ -180,69 +172,6 @@ public:
*/
static inline bool isVisible(sal_uInt32 nChar);
/** Check for US-ASCII digit character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII (decimal) digit character (US-
ASCII '0'--'9').
*/
static inline bool isDigit(sal_uInt32 nChar);
/** Check for US-ASCII canonic hexadecimal digit character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII canonic (i.e., upper case)
hexadecimal digit character (US-ASCII '0'--'9' or 'A'--'F').
*/
static inline bool isCanonicHexDigit(sal_uInt32 nChar);
/** Check for US-ASCII hexadecimal digit character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII hexadecimal digit character (US-
ASCII '0'--'9', 'A'--'F', 'a'--'f').
*/
static inline bool isHexDigit(sal_uInt32 nChar);
/** Check for US-ASCII upper case character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII upper case alphabetic character
(US-ASCII 'A'--'Z').
*/
static inline bool isUpperCase(sal_uInt32 nChar);
/** Check for US-ASCII lower case character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII lower case alphabetic character
(US-ASCII 'a'--'z').
*/
static inline bool isLowerCase(sal_uInt32 nChar);
/** Check for US-ASCII alphabetic character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII alphabetic character (US-ASCII
'A'--'Z' or 'a'--'z').
*/
static inline bool isAlpha(sal_uInt32 nChar);
/** Check for US-ASCII alphanumeric character.
@param nChar Some UCS-4 character.
@return True if nChar is a US-ASCII alphanumeric character (US-ASCII
'0'--'9', 'A'--'Z' or 'a'--'z').
*/
static inline bool isAlphanumeric(sal_uInt32 nChar);
/** Check for US-ASCII Base 64 digit character.
@param nChar Some UCS-4 character.
......@@ -301,6 +230,7 @@ public:
'A'--'Z'), return the corresponding US-ASCII lower case character (US-
ASCII 'a'--'z'); otherwise, return nChar unchanged.
*/
SAL_DEPRECATED("Use rtl::toAsciiUpperCase instead")
static inline sal_uInt32 toUpperCase(sal_uInt32 nChar);
/** Translate an US-ASCII character to lower case.
......@@ -311,6 +241,7 @@ public:
'a'--'z'), return the corresponding US-ASCII upper case character (US-
ASCII 'A'--'Z'); otherwise, return nChar unchanged.
*/
SAL_DEPRECATED("Use rtl::toAsciiLowerCase instead")
static inline sal_uInt32 toLowerCase(sal_uInt32 nChar);
/** Get the digit weight of a US-ASCII character.
......@@ -535,12 +466,6 @@ public:
sal_uInt32 nUTF32);
};
// static
inline bool INetMIME::isUSASCII(sal_uInt32 nChar)
{
return rtl::isAscii(nChar);
}
// static
inline bool INetMIME::isISO88591(sal_uInt32 nChar)
{
......@@ -565,48 +490,6 @@ inline bool INetMIME::isVisible(sal_uInt32 nChar)
return nChar >= '!' && nChar <= '~';
}
// static
inline bool INetMIME::isDigit(sal_uInt32 nChar)
{
return rtl::isAsciiDigit(nChar);
}
// static
inline bool INetMIME::isCanonicHexDigit(sal_uInt32 nChar)
{
return rtl::isAsciiCanonicHexDigit(nChar);
}
// static
inline bool INetMIME::isHexDigit(sal_uInt32 nChar)
{
return rtl::isAsciiHexDigit(nChar);
}
// static
inline bool INetMIME::isUpperCase(sal_uInt32 nChar)
{
return rtl::isAsciiUpperCase(nChar);
}
// static
inline bool INetMIME::isLowerCase(sal_uInt32 nChar)
{
return rtl::isAsciiLowerCase(nChar);
}
// static
inline bool INetMIME::isAlpha(sal_uInt32 nChar)
{
return rtl::isAsciiAlpha(nChar);
}
// static
inline bool INetMIME::isAlphanumeric(sal_uInt32 nChar)
{
return rtl::isAsciiAlphanumeric(nChar);
}
// static
inline bool INetMIME::isBase64Digit(sal_uInt32 nChar)
{
......@@ -617,13 +500,13 @@ inline bool INetMIME::isBase64Digit(sal_uInt32 nChar)
// static
inline sal_uInt32 INetMIME::toUpperCase(sal_uInt32 nChar)
{
return rtl::isAsciiLowerCase(nChar) ? nChar - ('a' - 'A') : nChar;
return rtl::toAsciiUpperCase(nChar);
}
// static
inline sal_uInt32 INetMIME::toLowerCase(sal_uInt32 nChar)
{
return rtl::isAsciiUpperCase(nChar) ? nChar + ('a' - 'A') : nChar;
return rtl::toAsciiLowerCase(nChar);
}
// static
......
......@@ -27,6 +27,7 @@
#include <string.h>
#include <sal/log.hxx>
#include <rtl/character.hxx>
#include <boost/static_assert.hpp>
/*
......@@ -179,10 +180,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase )( const IMPL_RTL_ST
/* 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;
c1 = rtl::toAsciiLowerCase( c1 );
c2 = rtl::toAsciiLowerCase( c2 );
nRet = c1-c2;
if ( nRet != 0 )
return nRet;
......@@ -205,19 +204,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;
sal_Int32 nRet;
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;
sal_uInt32 c1 = IMPL_RTL_USTRCODE( *pStr1 );
sal_uInt32 c2 = IMPL_RTL_USTRCODE( *pStr2 );
nRet = rtl::compareAsciiIgnoreCase(c1, c2);
if ( nRet != 0 )
return nRet;
......@@ -239,20 +231,13 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompareIgnoreAsciiCase_WithLength
{
const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len;
const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
sal_Int32 nRet;
sal_Int32 c1;
sal_Int32 c2;
sal_Int32 nRet;
while ( (nShortenedLength > 0) &&
(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;
sal_uInt32 c1 = IMPL_RTL_USTRCODE( *pStr1 );
sal_uInt32 c2 = IMPL_RTL_USTRCODE( *pStr2 );
nRet = rtl::compareAsciiIgnoreCase(c1, c2);
if ( nRet != 0 )
return nRet;
......@@ -577,9 +562,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase )( IMPL_RTL_STRCODE* pStr )
{
while ( *pStr )
{
/* Between A-Z (65-90), than to lowercase (+32) */
if ( (*pStr >= 65) && (*pStr <= 90) )
*pStr += 32;
*pStr = rtl::toAsciiLowerCase( *pStr );
pStr++;
}
......@@ -593,9 +576,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength )( IMPL_RTL_STRCODE*
{
while ( nLen > 0 )
{
/* Between A-Z (65-90), than to lowercase (+32) */
if ( (*pStr >= 65) && (*pStr <= 90) )
*pStr += 32;
*pStr = rtl::toAsciiLowerCase( *pStr );
pStr++;
nLen--;
......@@ -609,9 +590,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase )( IMPL_RTL_STRCODE* pStr )
{
while ( *pStr )
{
/* Between a-z (97-122), than to uppercase (-32) */
if ( (*pStr >= 97) && (*pStr <= 122) )
*pStr -= 32;
*pStr = rtl::toAsciiUpperCase( *pStr );
pStr++;
}
......@@ -625,9 +604,7 @@ void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase_WithLength )( IMPL_RTL_STRCODE*
{
while ( nLen > 0 )
{
/* Between a-z (97-122), than to uppercase (-32) */
if ( (*pStr >= 97) && (*pStr <= 122) )
*pStr -= 32;
*pStr = rtl::toAsciiUpperCase( *pStr );
pStr++;
nLen--;
......@@ -1592,7 +1569,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA**
while ( nLen > 0 )
{
/* Between A-Z (65-90), than to lowercase (+32) */
if ( (*pCharStr >= 65) && (*pCharStr <= 90) )
if ( rtl::isAsciiUpperCase(*pCharStr) )
{
/* Copy String */
IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
......@@ -1608,11 +1585,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA**
while ( nLen > 0 )
{
/* Between A-Z (65-90), than to lowercase (+32) */
if ( (*pCharStr >= 65) && (*pCharStr <= 90) )
*pNewCharStr = *pCharStr+32;
else
*pNewCharStr = *pCharStr;
*pNewCharStr = rtl::toAsciiLowerCase( *pCharStr );
pNewCharStr++;
pCharStr++;
......@@ -1654,7 +1627,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA**
while ( nLen > 0 )
{
/* Between a-z (97-122), than to uppercase (-32) */
if ( (*pCharStr >= 97) && (*pCharStr <= 122) )
if ( rtl::isAsciiLowerCase(*pCharStr) )
{
/* Copy String */
IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
......@@ -1670,11 +1643,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA**
while ( nLen > 0 )
{
/* Between a-z (97-122), than to uppercase (-32) */
if ( (*pCharStr >= 97) && (*pCharStr <= 122) )
*pNewCharStr = *pCharStr-32;
else
*pNewCharStr = *pCharStr;
*pNewCharStr = rtl::toAsciiUpperCase( *pCharStr );
pNewCharStr++;
pCharStr++;
......
......@@ -850,7 +850,7 @@ bool INetContentTypes::parse(OUString const & rMediaType,
bool bDowncase = false;
while (p != pEnd && INetMIME::isTokenChar(*p))
{
bDowncase = bDowncase || INetMIME::isUpperCase(*p);
bDowncase = bDowncase || rtl::isAsciiUpperCase(*p);
++p;
}
if (p == pToken)
......@@ -868,7 +868,7 @@ bool INetContentTypes::parse(OUString const & rMediaType,
bDowncase = false;
while (p != pEnd && INetMIME::isTokenChar(*p))
{
bDowncase = bDowncase || INetMIME::isUpperCase(*p);
bDowncase = bDowncase || rtl::isAsciiUpperCase(*p);
++p;
}
if (p == pToken)
......
......@@ -360,7 +360,7 @@ bool checkWChar(CharClass const & rCharClass, OUString const & rStr,
bool bPipe = false)
{
sal_Unicode c = rStr[*pPos];
if (INetMIME::isUSASCII(c))
if (rtl::isAscii(c))
{
static sal_uInt8 const aMap[128]
= { 0, 0, 0, 0, 0, 0, 0, 0,
......@@ -515,7 +515,7 @@ OUString URIHelper::FindFirstURLInText(OUString const & rText,
sal_Unicode c = rText[nPos];
if (bBoundary1)
{
if (INetMIME::isAlpha(c))
if (rtl::isAsciiAlpha(c))
{
sal_Int32 i = nPos;
INetProtocol eScheme = INetURLObject::CompareProtocolScheme(rText.copy(i, rEnd - i));
......
......@@ -26,7 +26,7 @@
#include <svx/sidebar/ValueSetWithTextControl.hxx>
#include <tools/inetmime.hxx>
#include <rtl/character.hxx>
#include <editeng/paperinf.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
......@@ -71,7 +71,7 @@ PageSizeControl::PageSizeControl(
for (short i = aText.getLength() - 1; i >= 0; i--)
{
sal_Unicode c = aText[i];
if ( INetMIME::isAlpha(c) || (c == '\'') || (c == '\"') || (c == '%') )
if ( rtl::isAsciiAlpha(c) || (c == '\'') || (c == '\"') || (c == '%') )
{
aMetricStr = OUString(c) + aMetricStr;
}
......
......@@ -30,6 +30,8 @@
#include "rtl/ustring.hxx"
#include "sal/types.h"
#include <rtl/character.hxx>
#include <algorithm>
#include <limits>
......@@ -562,7 +564,7 @@ static sal_uInt32 const aMustEncodeMap[128]
inline bool mustEncode(sal_uInt32 nUTF32, INetURLObject::Part ePart)
{
return !INetMIME::isUSASCII(nUTF32) || !(aMustEncodeMap[nUTF32] & ePart);
return !rtl::isAscii(nUTF32) || !(aMustEncodeMap[nUTF32] & ePart);
}
}
......@@ -2209,7 +2211,7 @@ INetURLObject::PrefixInfo const * INetURLObject::getPrefix(sal_Unicode const *&
}
if (p >= pEnd)
break;
sal_uInt32 nChar = INetMIME::toLowerCase(*p++);
sal_uInt32 nChar = rtl::toAsciiLowerCase(*p++);
while (pFirst <= pLast && sal_uChar(pFirst->m_pPrefix[i]) < nChar)
++pFirst;
while (pFirst <= pLast && sal_uChar(pLast->m_pPrefix[i]) > nChar)
......@@ -2219,7 +2221,7 @@ INetURLObject::PrefixInfo const * INetURLObject::getPrefix(sal_Unicode const *&
{
sal_Char const * q = pFirst->m_pPrefix + i;
while (p < pEnd && *q != '\0'
&& INetMIME::toLowerCase(*p) == sal_uChar(*q))
&& rtl::toAsciiLowerCase(*p) == sal_uChar(*q))
{
++p;
++q;
......@@ -3229,7 +3231,7 @@ bool INetURLObject::parsePath(INetProtocol eScheme,
eCharset, eEscapeType);
appendUCS4(aTheSynPath,
eEscapeType == ESCAPE_NO ?
INetMIME::toLowerCase(nUTF32) : nUTF32,
rtl::toAsciiLowerCase(nUTF32) : nUTF32,
eEscapeType, bOctets, PART_VIM, '=',
eCharset, false);
}
......@@ -3685,7 +3687,7 @@ OUString INetURLObject::decode(sal_Unicode const * pBegin,
case ESCAPE_UTF32:
if (
INetMIME::isUSASCII(nUTF32) &&
rtl::isAscii(nUTF32) &&
(
eMechanism == DECODE_TO_IURI ||
(
......@@ -5062,7 +5064,7 @@ sal_uInt32 INetURLObject::getUTF32(sal_Unicode const *& rBegin,
OSL_FAIL(
"INetURLObject::getUTF32(): Unsupported charset");
case RTL_TEXTENCODING_ASCII_US:
rEscapeType = INetMIME::isUSASCII(nUTF32) ?
rEscapeType = rtl::isAscii(nUTF32) ?
ESCAPE_UTF32 : ESCAPE_OCTET;
break;
......@@ -5071,7 +5073,7 @@ sal_uInt32 INetURLObject::getUTF32(sal_Unicode const *& rBegin,
break;
case RTL_TEXTENCODING_UTF8:
if (INetMIME::isUSASCII(nUTF32))
if (rtl::isAscii(nUTF32))
rEscapeType = ESCAPE_UTF32;
else
{
......
This diff is collapsed.
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