sc/source/filter/dif/difexp.cxx |   10 ++++------
 sc/source/ui/docshell/impex.cxx |   17 ++++++-----------
 2 files changed, 10 insertions(+), 17 deletions(-)

New commits:
commit bff60eadeac348024849d710690435ee9580831b
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Sat Sep 10 20:54:24 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Sun Sep 11 00:08:51 2022 +0200

    Simplify by using replaceAll instead of replaceAt (sc)
    
    It also shows more clearly the intention. Since replaceAt with "0" as 
second arg isn't a replace per se
    since it doesn't remove the first arg string.
    
    + get rid of lcl_DoubleEscapeChar which was used only once
    
    Change-Id: I08c38c6cfd016a6265725134cb87e518b51ab361
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139755
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/source/filter/dif/difexp.cxx b/sc/source/filter/dif/difexp.cxx
index 6fbd13ab2248..30df4a26fcce 100644
--- a/sc/source/filter/dif/difexp.cxx
+++ b/sc/source/filter/dif/difexp.cxx
@@ -210,12 +210,10 @@ void ScFormatFilterPluginImpl::ScExportDif( SvStream& 
rOut, ScDocument* pDoc,
                 aOS.setLength(0);
                 if ( eCharSet == RTL_TEXTENCODING_UNICODE )
                 {
-                    sal_Int32 nPos = aTmpStr.indexOf( cStrDelim );
-                    while ( nPos != -1 )
-                    {
-                        aTmpStr = aTmpStr.replaceAt( nPos, 0, 
rtl::OUStringChar(cStrDelim) );
-                        nPos = aTmpStr.indexOf( cStrDelim, nPos+2 );
-                    }
+                    // the goal is to replace cStrDelim by cStrDelim+cStrDelim
+                    OUString strFrom(cStrDelim);
+                    OUString strTo = strFrom + strFrom;
+                    aTmpStr = aTmpStr.replaceAll(strFrom, strTo);
                     rOut.WriteUniOrByteChar( cStrDelim, eCharSet );
                     write_uInt16s_FromOUString(rOut, aTmpStr);
                     rOut.WriteUniOrByteChar( cStrDelim, eCharSet );
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 6f2444e7ba05..59d8f9a3538c 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -887,20 +887,15 @@ static const sal_Unicode* lcl_ScanSylkFormula( const 
sal_Unicode* p,
     return p;
 }
 
-static void lcl_DoubleEscapeChar( OUString& rString, sal_Unicode cStr )
-{
-    sal_Int32 n = 0;
-    while( ( n = rString.indexOf( cStr, n ) ) != -1 )
-    {
-        rString = rString.replaceAt( n, 0, rtl::OUStringChar(cStr) );
-        n += 2;
-    }
-}
-
 static void lcl_WriteString( SvStream& rStrm, OUString& rString, sal_Unicode 
cQuote, sal_Unicode cEsc )
 {
     if (cEsc)
-        lcl_DoubleEscapeChar( rString, cEsc );
+    {
+        // the goal is to replace cStr by cStr+cStr
+        OUString strFrom(cEsc);
+        OUString strTo = strFrom + strFrom;
+        rString = rString.replaceAll(strFrom, strTo);
+    }
 
     if (cQuote)
     {

Reply via email to