bin/find-can-be-private-symbols.functions.results |    1 
 sc/inc/compiler.hxx                               |    2 -
 sc/source/core/tool/compiler.cxx                  |   32 +++++++---------------
 3 files changed, 11 insertions(+), 24 deletions(-)

New commits:
commit 3d1dc81b5e072862af17154b4f595fcaa4863d49
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Mon Sep 5 20:43:13 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue Sep 6 11:53:37 2022 +0200

    Simplify by using replace instead of replaceAt in loop in sc/compiler
    
    + replace ScCompiler::EnQuote which is used only once with its content at 
this adhoc location
    
    Change-Id: I7d72fd573ec9cea06d9b54e9381b4783756cf08e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139452
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/bin/find-can-be-private-symbols.functions.results 
b/bin/find-can-be-private-symbols.functions.results
index 89e04cb7696a..ee1bf33587e9 100644
--- a/bin/find-can-be-private-symbols.functions.results
+++ b/bin/find-can-be-private-symbols.functions.results
@@ -3296,7 +3296,6 @@ 
ScCompiler::CreateStringFromSingleRef(rtl::OUStringBuffer&, formula::FormulaToke
 ScCompiler::CreateStringFromXMLTokenArray(rtl::OUString&, rtl::OUString&)
 ScCompiler::DeInit()
 ScCompiler::DoubleRefToPosSingleRefScalarCase(ScRange const&, ScAddress&, 
ScAddress const&)
-ScCompiler::EnQuote(rtl::OUString&)
 ScCompiler::ExtendRangeReference(formula::FormulaToken&, 
formula::FormulaToken&)
 ScCompiler::FindAddInFunction(rtl::OUString const&, bool) const
 ScCompiler::GetAddInMapCount()
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index b7896c26c0e3..f45b6c14b9f9 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -416,8 +416,6 @@ public:
                  -1 if none. */
     static sal_Int32 GetDocTabPos( const OUString& rString );
 
-    static bool EnQuote( OUString& rStr );
-
     // Check if it is a valid english function name
     static bool IsEnglishSymbol( const OUString& rName );
 
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index cdcbdceac23f..2778472d1b88 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -5358,7 +5358,17 @@ void ScCompiler::CreateStringFromSingleRef( 
OUStringBuffer& rBuffer, const Formu
         if (rDoc.HasStringData(aAbs.Col(), aAbs.Row(), aAbs.Tab()))
         {
             OUString aStr = rDoc.GetString(aAbs, mpInterpreterContext);
-            EnQuote( aStr );
+
+            // If string contains only numeric characters or if it contains 
non-alphanumeric characters
+            // -> quote characters contained within are escaped by '\\'.
+            // -> put quotes around string
+            sal_Int32 nType = ScGlobal::getCharClass().getStringType( aStr, 0, 
aStr.getLength() );
+            if ( CharClass::isNumericType( nType )
+                || !CharClass::isAlphaNumericType( nType ) )
+            {
+                aStr = aStr.replaceAll(u"'", u"\\'");
+                aStr = "'" + aStr + "'";
+            }
             rBuffer.append(aStr);
         }
         else
@@ -5502,26 +5512,6 @@ void ScCompiler::LocalizeString( OUString& rName ) const
     ScGlobal::GetAddInCollection()->LocalizeString( rName );
 }
 
-// Put quotes around string if non-alphanumeric characters are contained
-// or if string contains only numeric characters,
-// quote characters contained within are escaped by '\\'.
-bool ScCompiler::EnQuote( OUString& rStr )
-{
-    sal_Int32 nType = ScGlobal::getCharClass().getStringType( rStr, 0, 
rStr.getLength() );
-    if ( !CharClass::isNumericType( nType )
-            && CharClass::isAlphaNumericType( nType ) )
-        return false;
-
-    sal_Int32 nPos = 0;
-    while ( (nPos = rStr.indexOf( '\'', nPos)) != -1 )
-    {
-        rStr = rStr.replaceAt( nPos, 0, u"\\" );
-        nPos += 2;
-    }
-    rStr = "'" + rStr + "'";
-    return true;
-}
-
 FormulaTokenRef ScCompiler::ExtendRangeReference( FormulaToken & rTok1, 
FormulaToken & rTok2 )
 {
     return extendRangeReference( rDoc.GetSheetLimits(), rTok1, rTok2, aPos, 
true/*bReuseDoubleRef*/ );

Reply via email to