diff options
author | Roman Kuznetsov <antilibreoffice@gmail.com> | 2022-07-06 10:18:02 +0200 |
---|---|---|
committer | Roman Kuznetsov <antilibreoffice@gmail.com> | 2022-07-13 14:57:10 +0200 |
commit | c2bf1ff91fab4574dd27808a2e4391c7a4b99d20 (patch) | |
tree | 53c3ee0512c217e6d8144f5db789eb6f585608b5 /basic | |
parent | dc82dd830bf4ef66451897624c946655a1526bde (diff) |
tdf#147132 Flatten a Basic function
Change-Id: I85eef5ca499197cfd96fecc4d05a82f7d11089cb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136856
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/runtime/methods.cxx | 114 |
1 files changed, 56 insertions, 58 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index fe654bbe6fd5..a397a31fddf5 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -889,78 +889,76 @@ void SbRtl_InStrRev(StarBASIC *, SbxArray & rPar, bool) const sal_uInt32 nArgCount = rPar.Count() - 1; if ( nArgCount < 2 ) { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); } - else - { - const OUString aStr1 = rPar.Get(1)->GetOUString(); - const OUString aToken = rPar.Get(2)->GetOUString(); - sal_Int32 nStartPos = -1; - if ( nArgCount >= 3 ) - { - nStartPos = rPar.Get(3)->GetLong(); - if( nStartPos <= 0 && nStartPos != -1 ) - { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - nStartPos = -1; - } - } + const OUString aStr1 = rPar.Get(1)->GetOUString(); + const OUString aToken = rPar.Get(2)->GetOUString(); - SbiInstance* pInst = GetSbData()->pInst; - bool bTextMode; - bool bCompatibility = ( pInst && pInst->IsCompatibility() ); - if( bCompatibility ) - { - SbiRuntime* pRT = pInst->pRun; - bTextMode = pRT && pRT->IsImageFlag( SbiImageFlags::COMPARETEXT ); - } - else - { - bTextMode = true; - } - if ( nArgCount == 4 ) + sal_Int32 nStartPos = -1; + if ( nArgCount >= 3 ) + { + nStartPos = rPar.Get(3)->GetLong(); + if( nStartPos <= 0 && nStartPos != -1 ) { - bTextMode = rPar.Get(4)->GetInteger(); + StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + nStartPos = -1; } - const sal_Int32 nStrLen = aStr1.getLength(); - if( nStartPos == -1 ) + } + + SbiInstance* pInst = GetSbData()->pInst; + bool bTextMode; + bool bCompatibility = ( pInst && pInst->IsCompatibility() ); + if( bCompatibility ) + { + SbiRuntime* pRT = pInst->pRun; + bTextMode = pRT && pRT->IsImageFlag( SbiImageFlags::COMPARETEXT ); + } + else + { + bTextMode = true; + } + if ( nArgCount == 4 ) + { + bTextMode = rPar.Get(4)->GetInteger(); + } + const sal_Int32 nStrLen = aStr1.getLength(); + if( nStartPos == -1 ) + { + nStartPos = nStrLen; + } + + sal_Int32 nPos = 0; + if( nStartPos <= nStrLen ) + { + sal_Int32 nTokenLen = aToken.getLength(); + if( !nTokenLen ) { - nStartPos = nStrLen; + // Always find empty string + nPos = nStartPos; } - - sal_Int32 nPos = 0; - if( nStartPos <= nStrLen ) + else if( nStrLen > 0 ) { - sal_Int32 nTokenLen = aToken.getLength(); - if( !nTokenLen ) + if( !bTextMode ) { - // Always find empty string - nPos = nStartPos; + nPos = aStr1.lastIndexOf( aToken, nStartPos ) + 1; } - else if( nStrLen > 0 ) + else { - if( !bTextMode ) - { - nPos = aStr1.lastIndexOf( aToken, nStartPos ) + 1; - } - else - { - // tdf#143332 - case-insensitive operation for non-ASCII characters - i18nutil::SearchOptions2 aSearchOptions; - aSearchOptions.searchString = aToken; - aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE; - aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE; - utl::TextSearch textSearch(aSearchOptions); - - sal_Int32 nStart = 0; - sal_Int32 nEnd = nStartPos; - nPos = textSearch.SearchBackward(aStr1, &nEnd, &nStart) ? nStart : 0; - } + // tdf#143332 - case-insensitive operation for non-ASCII characters + i18nutil::SearchOptions2 aSearchOptions; + aSearchOptions.searchString = aToken; + aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE; + aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE; + utl::TextSearch textSearch(aSearchOptions); + + sal_Int32 nStart = 0; + sal_Int32 nEnd = nStartPos; + nPos = textSearch.SearchBackward(aStr1, &nEnd, &nStart) ? nStart : 0; } } - rPar.Get(0)->PutLong(nPos); } + rPar.Get(0)->PutLong(nPos); } |