use more string_view in tools

Change-Id: I15ca12f35a66994cb90a0ccf60a1ce0f8efcfecc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133459
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2022-04-26 21:03:10 +02:00
parent 3791aff7ba
commit 05e75d86db
5 changed files with 25 additions and 19 deletions

View file

@ -76,7 +76,7 @@ public:
BigInt( sal_uInt32 nVal );
BigInt( sal_Int64 nVal );
BigInt( const BigInt& rBigInt );
BigInt( const OUString& rString );
BigInt( std::u16string_view rString );
operator sal_Int16() const;
operator sal_uInt16() const;

View file

@ -89,7 +89,7 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC StringRangeEnumerator
sal_Int32 mnOffset;
bool mbValidInput;
bool setRange( const OUString& i_rNewRange );
bool setRange( std::u16string_view i_rNewRange );
bool insertRange( sal_Int32 nFirst, sal_Int32 nLast, bool bSequence );
void insertJoinedRanges( const std::vector< sal_Int32 >& rNumbers );
bool checkValue( sal_Int32, const o3tl::sorted_vector< sal_Int32 >* i_pPossibleValues = nullptr ) const;
@ -119,7 +119,7 @@ public:
friend class StringRangeEnumerator::Iterator;
StringRangeEnumerator( const OUString& i_rInput,
StringRangeEnumerator( std::u16string_view i_rInput,
sal_Int32 i_nMinNumber,
sal_Int32 i_nMaxNumber,
sal_Int32 i_nLogicalOffset = -1
@ -155,7 +155,7 @@ public:
- single number that doesn't fit in [i_nMinNumber,i_nMaxNumber] will be ignored
- range that doesn't fit in [i_nMinNumber,i_nMaxNumber] will be adjusted
*/
static bool getRangesFromString( const OUString& i_rPageRange,
static bool getRangesFromString( std::u16string_view i_rPageRange,
std::vector< sal_Int32 >& o_rPageVector,
sal_Int32 i_nMinNumber,
sal_Int32 i_nMaxNumber,

View file

@ -1787,9 +1787,9 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
return (nSelectCount > 0) ? nSelectCount : 1;
}
static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, const OUString& rPagesStr, sal_Int32 nTotalPages )
static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, std::u16string_view rPagesStr, sal_Int32 nTotalPages )
{
if ( rPagesStr.isEmpty() )
if ( rPagesStr.empty() )
return nSelRenderer;
StringRangeEnumerator aRangeEnum( rPagesStr, 0, nTotalPages-1 );

View file

@ -475,20 +475,25 @@ BigInt::BigInt( const BigInt& rBigInt )
nVal = rBigInt.nVal;
}
BigInt::BigInt( const OUString& rString )
BigInt::BigInt( std::u16string_view rString )
: nLen(0)
{
bIsNeg = false;
nVal = 0;
bool bNeg = false;
const sal_Unicode* p = rString.getStr();
auto p = rString.begin();
auto pEnd = rString.end();
if (p == pEnd)
return;
if ( *p == '-' )
{
bNeg = true;
p++;
}
while( *p >= '0' && *p <= '9' )
if (p == pEnd)
return;
while( p != pEnd && *p >= '0' && *p <= '9' )
{
*this *= 10;
*this += *p - '0';

View file

@ -468,7 +468,7 @@ void MultiSelection::SetTotalRange( const Range& rTotRange )
// StringRangeEnumerator
StringRangeEnumerator::StringRangeEnumerator( const OUString& i_rInput,
StringRangeEnumerator::StringRangeEnumerator( std::u16string_view i_rInput,
sal_Int32 i_nMinNumber,
sal_Int32 i_nMaxNumber,
sal_Int32 i_nLogicalOffset
@ -566,18 +566,19 @@ void StringRangeEnumerator::insertJoinedRanges(
}
}
bool StringRangeEnumerator::setRange( const OUString& i_rNewRange )
bool StringRangeEnumerator::setRange( std::u16string_view aNewRange )
{
mnCount = 0;
maSequence.clear();
const sal_Unicode* pInput = i_rNewRange.getStr();
auto pInput = aNewRange.begin();
auto pInputEnd = aNewRange.end();
OUStringBuffer aNumberBuf( 16 );
std::vector< sal_Int32 > aNumbers;
bool bSequence = false;
while( *pInput )
while( pInput != pInputEnd )
{
while( *pInput >= '0' && *pInput <= '9' )
while( pInput != pInputEnd && *pInput >= '0' && *pInput <= '9' )
aNumberBuf.append( *pInput++ );
if( !aNumberBuf.isEmpty() )
{
@ -585,7 +586,8 @@ bool StringRangeEnumerator::setRange( const OUString& i_rNewRange )
aNumbers.push_back( nNumber );
bSequence = false;
}
if (pInput == pInputEnd)
break;
if( *pInput == '-' )
{
bSequence = true;
@ -607,10 +609,9 @@ bool StringRangeEnumerator::setRange( const OUString& i_rNewRange )
aNumbers.clear();
bSequence = false;
}
else if( *pInput && *pInput != ' ' )
else if( *pInput != ' ' )
return false; // parse error
if( *pInput )
pInput++;
}
// insert last entries
@ -710,7 +711,7 @@ StringRangeEnumerator::Iterator StringRangeEnumerator::end( const o3tl::sorted_v
return StringRangeEnumerator::Iterator( this, i_pPossibleValues, -1, -1 );
}
bool StringRangeEnumerator::getRangesFromString( const OUString& i_rPageRange,
bool StringRangeEnumerator::getRangesFromString( std::u16string_view i_rPageRange,
std::vector< sal_Int32 >& o_rPageVector,
sal_Int32 i_nMinNumber,
sal_Int32 i_nMaxNumber,