From 6fc3dfd3f1b5cb13101299df42444f2ff0493846 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 11 Apr 2022 14:49:08 +0200 Subject: use more string_view found by tweaking the loplugin:stringview and making it whitelist getLength Change-Id: Ic41cd4e3026d93b70a76fe1279c6de3abbe6b4a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132820 Tested-by: Jenkins Reviewed-by: Noel Grandin --- linguistic/source/dicimp.cxx | 10 +++++----- linguistic/source/dicimp.hxx | 6 +++--- linguistic/source/hhconvdic.cxx | 4 ++-- linguistic/source/misc.cxx | 26 +++++++++++++------------- 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'linguistic') diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx index d37990824f34..627cb2dd505b 100644 --- a/linguistic/source/dicimp.cxx +++ b/linguistic/source/dicimp.cxx @@ -499,8 +499,8 @@ void DictionaryNeo::launchEvent(sal_Int16 nEvent, aDicEvtListeners.notifyEach( &XDictionaryEventListener::processDictionaryEvent, aEvt); } -int DictionaryNeo::cmpDicEntry(const OUString& rWord1, - const OUString &rWord2, +int DictionaryNeo::cmpDicEntry(std::u16string_view rWord1, + std::u16string_view rWord2, bool bSimilarOnly) { MutexGuard aGuard( GetLinguMutex() ); @@ -511,8 +511,8 @@ int DictionaryNeo::cmpDicEntry(const OUString& rWord1, int nRes = 0; - sal_Int32 nLen1 = rWord1.getLength(), - nLen2 = rWord2.getLength(); + sal_Int32 nLen1 = rWord1.size(), + nLen2 = rWord2.size(); if (bSimilarOnly) { const sal_Unicode cChar = '.'; @@ -611,7 +611,7 @@ int DictionaryNeo::cmpDicEntry(const OUString& rWord1, return nRes; } -bool DictionaryNeo::seekEntry(const OUString &rWord, +bool DictionaryNeo::seekEntry(std::u16string_view rWord, sal_Int32 *pPos, bool bSimilarOnly) { // look for entry with binary search. diff --git a/linguistic/source/dicimp.hxx b/linguistic/source/dicimp.hxx index fdef09909519..cec1e1866ed3 100644 --- a/linguistic/source/dicimp.hxx +++ b/linguistic/source/dicimp.hxx @@ -63,10 +63,10 @@ class DictionaryNeo : ErrCode loadEntries(const OUString &rMainURL); ErrCode saveEntries(const OUString &rMainURL); - static int cmpDicEntry(const OUString &rWord1, - const OUString &rWord2, + static int cmpDicEntry(std::u16string_view rWord1, + std::u16string_view rWord2, bool bSimilarOnly = false); - bool seekEntry(const OUString &rWord, sal_Int32 *pPos, + bool seekEntry(std::u16string_view rWord, sal_Int32 *pPos, bool bSimilarOnly = false); bool isSorted(); diff --git a/linguistic/source/hhconvdic.cxx b/linguistic/source/hhconvdic.cxx index 76349a4d76ef..d20088a10e73 100644 --- a/linguistic/source/hhconvdic.cxx +++ b/linguistic/source/hhconvdic.cxx @@ -63,9 +63,9 @@ static sal_Int16 checkScriptType(sal_Unicode c) } -static bool TextIsAllScriptType( const OUString &rTxt, sal_Int16 nScriptType ) +static bool TextIsAllScriptType( std::u16string_view rTxt, sal_Int16 nScriptType ) { - for (sal_Int32 i = 0; i < rTxt.getLength(); ++i) + for (size_t i = 0; i < rTxt.size(); ++i) { if (checkScriptType( rTxt[i]) != nScriptType) return false; diff --git a/linguistic/source/misc.cxx b/linguistic/source/misc.cxx index c1e4cc7757d0..411361d38d66 100644 --- a/linguistic/source/misc.cxx +++ b/linguistic/source/misc.cxx @@ -96,11 +96,11 @@ bool LinguIsUnspecified( LanguageType nLanguage ) // For mappings between language code string and LanguageType see // i18nlangtag/source/isolang/isolang.cxx -bool LinguIsUnspecified( const OUString & rBcp47 ) +bool LinguIsUnspecified( std::u16string_view rBcp47 ) { - if (rBcp47.getLength() != 3) + if (rBcp47.size() != 3) return false; - return rBcp47 == "zxx" || rBcp47 == "und" || rBcp47 == "mul"; + return rBcp47 == u"zxx" || rBcp47 == u"und" || rBcp47 == u"mul"; } static sal_Int32 Minimum( sal_Int32 n1, sal_Int32 n2, sal_Int32 n3 ) @@ -139,10 +139,10 @@ sal_Int32 & IntArray2D::Value( int i, int k ) return pData[ i * n2 + k ]; } -sal_Int32 LevDistance( const OUString &rTxt1, const OUString &rTxt2 ) +sal_Int32 LevDistance( std::u16string_view rTxt1, std::u16string_view rTxt2 ) { - sal_Int32 nLen1 = rTxt1.getLength(); - sal_Int32 nLen2 = rTxt2.getLength(); + sal_Int32 nLen1 = rTxt1.size(); + sal_Int32 nLen2 = rTxt2.size(); if (nLen1 == 0) return nLen2; @@ -463,9 +463,9 @@ static bool GetAltSpelling( sal_Int16 &rnChgPos, sal_Int16 &rnChgLen, OUString & return bRes; } -static sal_Int16 GetOrigWordPos( const OUString &rOrigWord, sal_Int16 nPos ) +static sal_Int16 GetOrigWordPos( std::u16string_view rOrigWord, sal_Int16 nPos ) { - sal_Int32 nLen = rOrigWord.getLength(); + sal_Int32 nLen = rOrigWord.size(); sal_Int32 i = -1; while (nPos >= 0 && i++ < nLen) { @@ -477,10 +477,10 @@ static sal_Int16 GetOrigWordPos( const OUString &rOrigWord, sal_Int16 nPos ) return sal::static_int_cast< sal_Int16 >((0 <= i && i < nLen) ? i : -1); } -sal_Int32 GetPosInWordToCheck( const OUString &rTxt, sal_Int32 nPos ) +sal_Int32 GetPosInWordToCheck( std::u16string_view rTxt, sal_Int32 nPos ) { sal_Int32 nRes = -1; - sal_Int32 nLen = rTxt.getLength(); + sal_Int32 nLen = rTxt.size(); if (0 <= nPos && nPos < nLen) { nRes = 0; @@ -645,12 +645,12 @@ bool HasDigits( const OUString &rText ) return false; } -bool IsNumeric( const OUString &rText ) +bool IsNumeric( std::u16string_view rText ) { bool bRes = false; - if (!rText.isEmpty()) + if (!rText.empty()) { - sal_Int32 nLen = rText.getLength(); + sal_Int32 nLen = rText.size(); bRes = true; for(sal_Int32 i = 0; i < nLen; ++i) { -- cgit