summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-11-24 12:52:22 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-12-01 15:49:17 +0100
commit59a90439a4e1d26e53008451237388fd26a8adf6 (patch)
tree3dfd0469183926ad737eccc13969b13f77ae8f91 /basic
parent1d45f84bd08c8d196fcf3c9baaf2cad010884e5c (diff)
Simplify ImpStrChr and ImpScan
Change-Id: I8c752a7838ded7f3783982411ec937f46224d522 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126172 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic')
-rw-r--r--basic/source/sbx/sbxscan.cxx33
1 files changed, 7 insertions, 26 deletions
diff --git a/basic/source/sbx/sbxscan.cxx b/basic/source/sbx/sbxscan.cxx
index a496a51d6ccb..e6037d05cbcd 100644
--- a/basic/source/sbx/sbxscan.cxx
+++ b/basic/source/sbx/sbxscan.cxx
@@ -59,21 +59,7 @@ void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep, sal
}
-/** NOTE: slightly differs from strchr() in that it does not consider the
- terminating NULL character to be part of the string and returns bool
- instead of pointer, if character is 0 returns false.
- */
-static bool ImpStrChr( const sal_Unicode* p, sal_Unicode c )
-{
- if (!c)
- return false;
- while (*p)
- {
- if (*p++ == c)
- return true;
- }
- return false;
-}
+static bool ImpStrChr( const OUString& str, sal_Unicode c ) { return str.indexOf(c) >= 0; }
// scanning a string according to BASIC-conventions
@@ -134,8 +120,8 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
aSearchStr.append(cIntntlDecSepAlt);
if( bOnlyIntntl )
aSearchStr.append(cIntntlGrpSep);
- const sal_Unicode* const pSearchStr = aSearchStr.getStr();
- const sal_Unicode pDdEe[] = { 'D', 'd', 'E', 'e', 0 };
+ const OUString pSearchStr = aSearchStr.makeStringAndClear();
+ static const OUStringLiteral pDdEe = u"DdEe";
while( ImpStrChr( pSearchStr, *p ) )
{
aBuf.append( *p );
@@ -205,7 +191,7 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
eScanType = SbxDOUBLE;
// type detection?
- const sal_Unicode pTypes[] = { '%', '!', '&', '#', 0 };
+ static const OUStringLiteral pTypes = u"%!&#";
if( ImpStrChr( pTypes, *p ) )
p++;
}
@@ -214,7 +200,7 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
{
p++;
eScanType = SbxLONG;
- OUString aCmp( "0123456789ABCDEFabcdef" );
+ OUString aCmp( "0123456789ABCDEF" );
char base = 16;
char ndig = 8;
switch( *p++ )
@@ -231,16 +217,11 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
default :
bRes = false;
}
- const sal_Unicode* const pCmp = aCmp.getStr();
while( rtl::isAsciiAlphanumeric( *p ) ) /* XXX: really munge all alnum also when error? */
{
- sal_Unicode ch = *p;
- if( ImpStrChr( pCmp, ch ) )
- {
- if (ch > 0x60)
- ch -= 0x20; // convert ASCII lower to upper case
+ sal_Unicode ch = rtl::toAsciiUpperCase(*p);
+ if( ImpStrChr( aCmp, ch ) )
aBuf.append( ch );
- }
else
bRes = false;
p++;