summaryrefslogtreecommitdiff
path: root/basic/source
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-07-15 20:43:32 +0200
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2021-07-16 09:29:16 +0200
commitafddd56a8049957b9c0e025992d47c04342dbb88 (patch)
tree2a9bc9cb134de253cfa4eee28dbfaac7952241a5 /basic/source
parente7b632bc727413f399a4d0cbc2e92d90b04a3bf7 (diff)
tdf#139840 - Use utl::TextSearch to implement the InStr function
In addtion, fixed a crash if the start position is greater than the length of the string being searched. Change-Id: I9bcda1131324bdfac6957018e91b3a36dd2dc3d6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118996 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Diffstat (limited to 'basic/source')
-rw-r--r--basic/source/runtime/methods.cxx37
1 files changed, 22 insertions, 15 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index e745fa2fd1c6..1055aab142d2 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -885,25 +885,32 @@ void SbRtl_InStr(StarBASIC *, SbxArray & rPar, bool)
}
else
{
- if( !bTextMode )
+ const OUString& rStr1 = rPar.Get(nFirstStringPos)->GetOUString();
+ const sal_Int32 nrStr1Len = rStr1.getLength();
+ if (nStartPos > nrStr1Len)
{
- const OUString& rStr1 = rPar.Get(nFirstStringPos)->GetOUString();
- nPos = rStr1.indexOf( rToken, nStartPos - 1 ) + 1;
+ // Start position is greater than the string being searched
+ nPos = 0;
}
else
{
- OUString aStr1 = rPar.Get(nFirstStringPos)->GetOUString();
- OUString aToken = rToken;
-
- // tdf#139840 - case-insensitive operation for non-ASCII characters
- const css::lang::Locale& rLocale
- = Application::GetSettings().GetLanguageTag().getLocale();
- css::uno::Reference<i18n::XCharacterClassification> xCharClass
- = vcl::unohelper::CreateCharacterClassification();
- aStr1 = xCharClass->toUpper(aStr1, 0, aStr1.getLength(), rLocale);
- aToken = xCharClass->toUpper(aToken, 0, aToken.getLength(), rLocale);
-
- nPos = aStr1.indexOf( aToken, nStartPos-1 ) + 1;
+ if( !bTextMode )
+ {
+ nPos = rStr1.indexOf( rToken, nStartPos - 1 ) + 1;
+ }
+ else
+ {
+ // tdf#139840 - case-insensitive operation for non-ASCII characters
+ i18nutil::SearchOptions2 aSearchOptions;
+ aSearchOptions.searchString = rToken;
+ aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE;
+ aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
+ utl::TextSearch textSearch(aSearchOptions);
+
+ sal_Int32 nStart = nStartPos - 1;
+ sal_Int32 nEnd = nrStr1Len;
+ nPos = textSearch.SearchForward(rStr1, &nStart, &nEnd) ? nStart + 1 : 0;
+ }
}
}
rPar.Get(0)->PutLong(nPos);