summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-04-07 10:46:26 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-04-08 10:26:10 +0200
commit3a88b513fd90f4793b6de7a7412fa33369542f40 (patch)
tree293467f4143a28a2a19f037f3215f4391794c854 /basic
parent388b4fc1085074da759903a9b1768bded43dd0d3 (diff)
loplugin:stringviewparam convert methods using trim
for which we add a new o3tl::trim method Change-Id: I9d37b6264eea106aa2f3502bd24b8cccf7850938 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132658 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basic')
-rw-r--r--basic/source/sbx/sbxcurr.cxx36
1 files changed, 17 insertions, 19 deletions
diff --git a/basic/source/sbx/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx
index 416229afbc95..ad558f2284c1 100644
--- a/basic/source/sbx/sbxcurr.cxx
+++ b/basic/source/sbx/sbxcurr.cxx
@@ -21,6 +21,7 @@
#include <basic/sberrors.hxx>
#include <basic/sbxvar.hxx>
+#include <o3tl/string_view.hxx>
#include "sbxconv.hxx"
@@ -85,7 +86,7 @@ static OUString ImpCurrencyToString( sal_Int64 rVal )
}
-static sal_Int64 ImpStringToCurrency( const OUString &rStr )
+static sal_Int64 ImpStringToCurrency( std::u16string_view rStr )
{
sal_Int32 nFractDigit = 4;
@@ -99,50 +100,47 @@ static sal_Int64 ImpStringToCurrency( const OUString &rStr )
// we should share some existing ( possibly from calc is there a currency
// conversion there ? #TODO check )
- OUString sTmp( rStr.trim() );
- const sal_Unicode* p = sTmp.getStr();
+ std::u16string_view sTmp = o3tl::trim( rStr );
+ auto p = sTmp.begin();
+ auto pEnd = sTmp.end();
// normalise string number by removing thousand & decimal point separators
- OUStringBuffer sNormalisedNumString( sTmp.getLength() + nFractDigit );
+ OUStringBuffer sNormalisedNumString( static_cast<sal_Int32>(sTmp.size()) + nFractDigit );
- if ( *p == '-' || *p == '+' )
+ if ( p != pEnd && (*p == '-' || *p == '+' ) )
sNormalisedNumString.append( *p++ );
- while ( *p >= '0' && *p <= '9' )
+ while ( p != pEnd && *p >= '0' && *p <= '9' )
{
sNormalisedNumString.append( *p++ );
// #TODO in vba mode set runtime error when a space ( or other )
// illegal character is found
- if( *p == c1000Sep )
+ if( p != pEnd && *p == c1000Sep )
p++;
}
bool bRoundUp = false;
- if( *p == cDeciPnt )
+ if( p != pEnd && *p == cDeciPnt )
{
p++;
- while( nFractDigit && *p >= '0' && *p <= '9' )
+ while( nFractDigit && p != pEnd && *p >= '0' && *p <= '9' )
{
sNormalisedNumString.append( *p++ );
nFractDigit--;
}
// Consume trailing content
- if ( p != nullptr )
- {
- // Round up if necessary
- if( *p >= '5' && *p <= '9' )
- bRoundUp = true;
- while( *p >= '0' && *p <= '9' )
- p++;
- }
-
+ // Round up if necessary
+ if( p != pEnd && *p >= '5' && *p <= '9' )
+ bRoundUp = true;
+ while( p != pEnd && *p >= '0' && *p <= '9' )
+ p++;
}
// can we raise error here ? ( previous behaviour was more forgiving )
// so... not sure that could break existing code, let's see if anyone
// complains.
- if ( p != sTmp.getStr() + sTmp.getLength() )
+ if ( p != pEnd )
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
while( nFractDigit )
{