summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2022-09-23 07:41:23 -0400
committerJustin Luth <jluth@mail.com>2022-09-23 17:38:15 +0200
commit3bfed17b047422a8c4e98ab80001f3158afb227e (patch)
tree127346903168225dc801c8834e6d4238861bc638 /sc
parent23cbe9b969db11f9fb25d8dffe8d801e002b5e94 (diff)
tdf#123990 sc condformat: case insensitive begins/ends/contains
This is how Excel handles these. At first I was afraid that this would upset LibreOffice users, but then I realized that equals already is case insensitive, so this change ought to be more consistent, and thus there should be fewer outcrys. Change-Id: Ia3de78d5888672ba8b774866d41ecd65293397c1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140484 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc_condformat.cxx3
-rw-r--r--sc/source/core/data/conditio.cxx28
2 files changed, 26 insertions, 5 deletions
diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx
index 652ca8b059c6..35a8a02b0802 100644
--- a/sc/qa/unit/ucalc_condformat.cxx
+++ b/sc/qa/unit/ucalc_condformat.cxx
@@ -818,7 +818,8 @@ void TestCondformat::testCondFormatEndsWithStr()
{
m_pDoc->InsertTab(0, "Test");
- ScConditionEntry aEntry(ScConditionMode::EndsWith, "\"TestString\"", "", *m_pDoc, ScAddress(),
+ // case insnsitive matching
+ ScConditionEntry aEntry(ScConditionMode::EndsWith, "\"teststring\"", "", *m_pDoc, ScAddress(),
"", "", formula::FormulaGrammar::GRAM_DEFAULT, formula::FormulaGrammar::GRAM_DEFAULT);
svl::SharedStringPool& rStringPool = m_pDoc->GetSharedStringPool();
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 46e51cf9f297..834c4a78f5e8 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -1175,14 +1175,34 @@ bool ScConditionEntry::IsValidStr( const OUString& rArg, const ScAddress& rPos )
bValid = !bValid;
break;
case ScConditionMode::BeginsWith:
- bValid = rArg.startsWith(aUpVal1);
- break;
+ {
+ const sal_Int32 nLen = aUpVal1.getLength();
+ if (!nLen || nLen > rArg.getLength())
+ bValid = false;
+ else
+ {
+ bValid = (ScGlobal::GetCollator().compareSubstring(rArg, 0, nLen,
+ aUpVal1, 0, nLen) == 0);
+ }
+ }
+ break;
case ScConditionMode::EndsWith:
- bValid = rArg.endsWith(aUpVal1);
+ {
+ sal_Int32 nStart = rArg.getLength();
+ const sal_Int32 nLen = aUpVal1.getLength();
+ if (!nLen || nLen > nStart)
+ bValid = false;
+ else
+ {
+ nStart = nStart - nLen;
+ bValid = (ScGlobal::GetCollator().compareSubstring(rArg, nStart, nLen,
+ aUpVal1, 0, nLen) == 0);
+ }
+ }
break;
case ScConditionMode::ContainsText:
case ScConditionMode::NotContainsText:
- bValid = rArg.indexOf(aUpVal1) != -1;
+ bValid = rArg.toAsciiLowerCase().indexOf(aUpVal1.toAsciiLowerCase()) != -1;
if(eOp == ScConditionMode::NotContainsText)
bValid = !bValid;
break;