summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2022-09-12 17:14:24 +0200
committerEike Rathke <erack@redhat.com>2022-09-13 10:25:17 +0200
commitab0adac692b67fe7b63dee665607400c6a7e6c01 (patch)
treeb67f36216dcf5f06e6acd4d73cbd629a4f81b14d /unotools
parentf0f0d385b91df30d4ec42a9f727cbdbe5ce0861f (diff)
Fix everything using XCharacterClassification::getStringType() and don't use it
See note in offapi/com/sun/star/i18n/XCharacterClassification.idl The brain dead implementation is useless but API ... its use in isAlphaNumericType() and similar never returned what would had been expected. Change-Id: I278f2468182dab94c32273ef69cf9634bc002cb4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139809 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/i18n/charclass.cxx83
1 files changed, 65 insertions, 18 deletions
diff --git a/unotools/source/i18n/charclass.cxx b/unotools/source/i18n/charclass.cxx
index ace153d03a74..4573687c4d29 100644
--- a/unotools/source/i18n/charclass.cxx
+++ b/unotools/source/i18n/charclass.cxx
@@ -134,7 +134,14 @@ bool CharClass::isLetter( const OUString& rStr ) const
{
try
{
- return isLetterType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) );
+ sal_Int32 nPos = 0;
+ while (nPos < rStr.getLength())
+ {
+ if (!isLetter( rStr, nPos))
+ return false;
+ rStr.iterateCodePoints( &nPos);
+ }
+ return true;
}
catch ( const Exception& )
{
@@ -165,7 +172,14 @@ bool CharClass::isNumeric( const OUString& rStr ) const
{
try
{
- return isNumericType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) );
+ sal_Int32 nPos = 0;
+ while (nPos < rStr.getLength())
+ {
+ if (!isDigit( rStr, nPos))
+ return false;
+ rStr.iterateCodePoints( &nPos);
+ }
+ return true;
}
catch ( const Exception& )
{
@@ -183,7 +197,7 @@ bool CharClass::isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const
try
{
return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) &
- (nCharClassAlphaType | KCharacterType::DIGIT)) != 0;
+ (nCharClassAlphaType | nCharClassNumericType)) != 0;
}
catch ( const Exception& )
{
@@ -201,7 +215,7 @@ bool CharClass::isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const
try
{
return (xCC->getCharacterType( rStr, nPos, getMyLocale() ) &
- (nCharClassLetterType | KCharacterType::DIGIT)) != 0;
+ (nCharClassLetterType | nCharClassNumericType)) != 0;
}
catch ( const Exception& )
{
@@ -214,7 +228,53 @@ bool CharClass::isLetterNumeric( const OUString& rStr ) const
{
try
{
- return isLetterNumericType( xCC->getStringType( rStr, 0, rStr.getLength(), getMyLocale() ) );
+ sal_Int32 nPos = 0;
+ while (nPos < rStr.getLength())
+ {
+ if (!isLetterNumeric( rStr, nPos))
+ return false;
+ rStr.iterateCodePoints( &nPos);
+ }
+ return true;
+ }
+ catch ( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION("unotools.i18n", "" );
+ }
+ return false;
+}
+
+bool CharClass::isUpper( const OUString& rStr, sal_Int32 nPos ) const
+{
+ sal_Unicode c = rStr[nPos];
+ if ( c < 128 )
+ return rtl::isAsciiUpperCase(c);
+
+ try
+ {
+ return (xCC->getCharacterType( rStr, nPos, getMyLocale()) &
+ KCharacterType::UPPER) != 0;
+ }
+ catch ( const Exception& )
+ {
+ TOOLS_WARN_EXCEPTION("unotools.i18n", "" );
+ }
+ return false;
+}
+
+bool CharClass::isUpper( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const
+{
+ try
+ {
+ assert(nPos >= 0 && nCount >= 0);
+ sal_Int32 nLen = std::min( nPos + nCount, rStr.getLength());
+ while (nPos < nLen)
+ {
+ if (!isUpper( rStr, nPos))
+ return false;
+ rStr.iterateCodePoints( &nPos);
+ }
+ return true;
}
catch ( const Exception& )
{
@@ -314,19 +374,6 @@ sal_Int32 CharClass::getCharacterType( const OUString& rStr, sal_Int32 nPos ) co
return 0;
}
-sal_Int32 CharClass::getStringType( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const
-{
- try
- {
- return xCC->getStringType( rStr, nPos, nCount, getMyLocale() );
- }
- catch ( const Exception& )
- {
- TOOLS_WARN_EXCEPTION("unotools.i18n", "" );
- }
- return 0;
-}
-
css::i18n::ParseResult CharClass::parseAnyToken(
const OUString& rStr,
sal_Int32 nPos,