include/unotools/collatorwrapper.hxx     |    3 ---
 sc/source/core/data/conditio.cxx         |   27 ++++++++++++---------------
 unotools/source/i18n/collatorwrapper.cxx |   17 -----------------
 3 files changed, 12 insertions(+), 35 deletions(-)

New commits:
commit 27c22bac5439908ecdd1aa05580d75998a5eb058
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Mon Sep 26 18:15:03 2022 -0400
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue Sep 27 21:55:02 2022 +0200

    tdf#123990 sc condition: use GetTransliteration, not GetCollator
    
    Thanks Eike
    
    Eike said "This should not use collation (which should only be used
    in sorting context) but ignore case transliteration instead."
    
    I had just copied ancient code from
    commit 952c2b02c73b30b011306faf2f0d6f2b4a935955
    Author: Eike Rathke on Date:   Wed Mar 14 14:57:39 2001 +0000
        use CollatorWrapper instead of International
    
    Apparently that code should also be changed
    in a follow-up commit.
    
    Interestingly, a \x000 - \x008 etc must be isEqual(""),
    so an attempt to ScGlobal::getCharClass().lowercase
    all variables at the beginning and use regular OUString
    comparisons didn't work.
    
    Also, a "" startsWith and endsWith each string.
    In Excel, a "" is also contained in every string,
    but not (yet) in Calc.
    
    Change-Id: I44a07c482d2d67a76a939ba2d593a003398d52c0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140633
    Tested-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/include/unotools/collatorwrapper.hxx 
b/include/unotools/collatorwrapper.hxx
index 1552a7ce9b36..595d9ccf4f41 100644
--- a/include/unotools/collatorwrapper.hxx
+++ b/include/unotools/collatorwrapper.hxx
@@ -45,9 +45,6 @@ class UNOTOOLS_DLLPUBLIC CollatorWrapper
         compareString (
                 const OUString& s1, const OUString& s2) const;
 
-        sal_Int32 compareSubstring (const OUString& s1, sal_Int32 off1, 
sal_Int32 len1,
-                                    const OUString& s2, sal_Int32 off2, 
sal_Int32 len2) const;
-
         css::uno::Sequence< OUString >
         listCollatorAlgorithms (
                 const css::lang::Locale& rLocale) const;
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 834c4a78f5e8..d126357dc38a 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -1175,36 +1175,33 @@ bool ScConditionEntry::IsValidStr( const OUString& 
rArg, const ScAddress& rPos )
                 bValid = !bValid;
         break;
         case ScConditionMode::BeginsWith:
-        {
-            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;
+            bValid = ScGlobal::GetTransliteration().isMatch(aUpVal1, rArg);
+        break;
         case ScConditionMode::EndsWith:
         {
             sal_Int32 nStart = rArg.getLength();
             const sal_Int32 nLen = aUpVal1.getLength();
-            if (!nLen || nLen > nStart)
+            if (nLen > nStart)
                 bValid = false;
             else
             {
                 nStart = nStart - nLen;
-                bValid = (ScGlobal::GetCollator().compareSubstring(rArg, 
nStart, nLen,
-                                                                   aUpVal1, 0, 
nLen) == 0);
+                sal_Int32 nMatch1(0), nMatch2(0);
+                bValid = ScGlobal::GetTransliteration().equals(rArg, nStart, 
nLen, nMatch1,
+                                                               aUpVal1, 0, 
nLen, nMatch2);
             }
         }
         break;
         case ScConditionMode::ContainsText:
         case ScConditionMode::NotContainsText:
-            bValid = 
rArg.toAsciiLowerCase().indexOf(aUpVal1.toAsciiLowerCase()) != -1;
+        {
+            const OUString aArgStr(ScGlobal::getCharClass().lowercase(rArg));
+            const OUString 
aValStr(ScGlobal::getCharClass().lowercase(aUpVal1));
+            bValid = aArgStr.indexOf(aValStr) != -1;
+
             if(eOp == ScConditionMode::NotContainsText)
                 bValid = !bValid;
+        }
         break;
         default:
         {
diff --git a/unotools/source/i18n/collatorwrapper.cxx 
b/unotools/source/i18n/collatorwrapper.cxx
index ce85de11df7e..4da1398e0636 100644
--- a/unotools/source/i18n/collatorwrapper.cxx
+++ b/unotools/source/i18n/collatorwrapper.cxx
@@ -46,23 +46,6 @@ CollatorWrapper::compareString (const OUString& s1, const 
OUString& s2) const
     return 0;
 }
 
-sal_Int32
-CollatorWrapper::compareSubstring (const OUString& s1, sal_Int32 off1, 
sal_Int32 len1,
-                                   const OUString& s2, sal_Int32 off2, 
sal_Int32 len2) const
-{
-    try
-    {
-        if (mxInternationalCollator.is())
-            return mxInternationalCollator->compareSubstring (s1, off1, len1, 
s2, off2, len2);
-    }
-    catch (const uno::RuntimeException&)
-    {
-        SAL_WARN( "unotools.i18n","CollatorWrapper: compareSubstring failed");
-    }
-
-    return 0;
-}
-
 uno::Sequence< OUString >
 CollatorWrapper::listCollatorAlgorithms (const lang::Locale& rLocale) const
 {

Reply via email to