[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - sc/inc sc/source

Eike Rathke erack at redhat.com
Fri Nov 8 15:51:48 CET 2013


 sc/inc/global.hxx               |   13 +++++++++++++
 sc/source/core/data/global.cxx  |   15 +++++++++++++++
 sc/source/ui/dbgui/filtdlg.cxx  |    4 +---
 sc/source/ui/dbgui/pfiltdlg.cxx |    4 +---
 sc/source/ui/dbgui/tpsort.cxx   |   11 ++---------
 sc/source/ui/dbgui/tpsubt.cxx   |    4 +---
 6 files changed, 33 insertions(+), 18 deletions(-)

New commits:
commit 3fff431f152f23180e2ce58e7d1dc6b6b45ab332
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Nov 8 14:22:21 2013 +0100

    "%1 is replaced to ..." ... maybe, or maybe not
    
    Translations may have omitted the %1 placeholder in SCSTR_COLUMN and
    SCSTR_ROW, or not have it translated newly yet because it was introduced
    later. In these cases append the column indicator / row number as it was
    done before.
    
    (cherry picked from commit 9b10373edae490d2b9b7f8d733c59b4f63927bec)
    
    Conflicts:
    	sc/source/ui/dbgui/filtdlg.cxx
    	sc/source/ui/dbgui/pfiltdlg.cxx
    	sc/source/ui/dbgui/tpsort.cxx
    	sc/source/ui/dbgui/tpsubt.cxx
    
    Change-Id: I331cf0c529bebea02277784ea145c202eb6f6fda
    Reviewed-on: https://gerrit.libreoffice.org/6618
    Reviewed-by: Ivan Timofeev <timofeev.i.s at gmail.com>
    Tested-by: Ivan Timofeev <timofeev.i.s at gmail.com>

diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index a3f89fb..66f3320 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -704,6 +704,19 @@ SC_DLLPUBLIC    static const sal_Unicode* FindUnquoted( const sal_Unicode* pStri
     /** A static instance of ScFieldEditEngine not capable of resolving
         document specific fields, to be used only by ScEditUtil::GetString(). */
     static ScFieldEditEngine&   GetStaticFieldEditEngine();
+
+    /** Replaces the first occurrence of rPlaceholder in rString with
+        rReplacement, or if rPlaceholder is not found appends one space if
+        rString does not end in a space and appends rReplacement.
+
+        Meant to be used with resource strings ala "Column %1" where a
+        translation may have omitted the %1 placeholder and a simple
+        replacement would end up with nothing replaced so no column indicator
+        in the result string.
+     */
+    SC_DLLPUBLIC static OUString    ReplaceOrAppend( const OUString& rString,
+                                                     const OUString& rPlaceholder,
+                                                     const OUString& rReplacement );
 };
 #endif
 
diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx
index f75b936..846ca77 100644
--- a/sc/source/core/data/global.cxx
+++ b/sc/source/core/data/global.cxx
@@ -1206,4 +1206,19 @@ ScFieldEditEngine& ScGlobal::GetStaticFieldEditEngine()
     return *pFieldEditEngine;
 }
 
+OUString ScGlobal::ReplaceOrAppend( const OUString& rString,
+        const OUString& rPlaceholder, const OUString& rReplacement )
+{
+    if (rString.isEmpty())
+        return rReplacement;
+    sal_Int32 nFound = rString.indexOf( rPlaceholder);
+    if (nFound < 0)
+    {
+        if (rString[rString.getLength()-1] == ' ')
+            return rString + rReplacement;
+        return rString + " " + rReplacement;
+    }
+    return rString.replaceFirst( rPlaceholder, rReplacement, &nFound);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/dbgui/filtdlg.cxx b/sc/source/ui/dbgui/filtdlg.cxx
index 61f5ecb..8e39046 100644
--- a/sc/source/ui/dbgui/filtdlg.cxx
+++ b/sc/source/ui/dbgui/filtdlg.cxx
@@ -488,9 +488,7 @@ void ScFilterDlg::FillFieldLists()
             aFieldName = pDoc->GetString(col, nFirstRow, nTab);
             if (!aBtnHeader.IsChecked() || aFieldName.isEmpty())
             {
-                OUStringBuffer aBuf;
-                aBuf.append(aStrColumn);
-                aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+                aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
             }
             aLbField1.InsertEntry( aFieldName, i );
             aLbField2.InsertEntry( aFieldName, i );
diff --git a/sc/source/ui/dbgui/pfiltdlg.cxx b/sc/source/ui/dbgui/pfiltdlg.cxx
index 3f5f63e..95cec1c 100644
--- a/sc/source/ui/dbgui/pfiltdlg.cxx
+++ b/sc/source/ui/dbgui/pfiltdlg.cxx
@@ -294,9 +294,7 @@ void ScPivotFilterDlg::FillFieldLists()
             aFieldName = pDoc->GetString(col, nFirstRow, nTab);
             if ( aFieldName.isEmpty() )
             {
-               OUStringBuffer aBuf;
-                aBuf.append(aStrColumn);
-                aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+                aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
             }
             aLbField1.InsertEntry( aFieldName, i );
             aLbField2.InsertEntry( aFieldName, i );
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index 1479313..a0520ea 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -384,9 +384,7 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField )
                     aFieldName = pDoc->GetString(col, nFirstSortRow, nTab);
                     if ( !bHasHeader || aFieldName.isEmpty() )
                     {
-                        OUStringBuffer aBuf;
-                        aBuf.append(aStrColumn);
-                        aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+                        aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
                     }
                     nFieldArr.push_back( col );
 
@@ -407,12 +405,7 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField )
                     aFieldName = pDoc->GetString(nFirstSortCol, row, nTab);
                     if ( !bHasHeader || aFieldName.isEmpty() )
                     {
-                        OUStringBuffer aBuf;
-                        OUStringBuffer tempBuf;
-
-                        aBuf.append(aStrRow);
-                        tempBuf.append(row+1 );
-                        aFieldName = aBuf.makeStringAndClear().replaceAll("%1", tempBuf.makeStringAndClear());
+                        aFieldName = ScGlobal::ReplaceOrAppend( aStrRow, "%1", OUString::number( row+1));
                     }
                     nFieldArr.push_back( row );
 
diff --git a/sc/source/ui/dbgui/tpsubt.cxx b/sc/source/ui/dbgui/tpsubt.cxx
index b2a9f9a..1431362 100644
--- a/sc/source/ui/dbgui/tpsubt.cxx
+++ b/sc/source/ui/dbgui/tpsubt.cxx
@@ -278,9 +278,7 @@ void ScTpSubTotalGroup::FillListBoxes()
             aFieldName = pDoc->GetString(col, nFirstRow, nTab);
             if ( aFieldName.isEmpty() )
             {
-                OUStringBuffer aBuf;
-                aBuf.append(aStrColumn);
-                aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
+                aFieldName = ScGlobal::ReplaceOrAppend( aStrColumn, "%1", ScColToAlpha( col ));
             }
             nFieldArr[i] = col;
             aLbGroup.InsertEntry( aFieldName, i+1 );


More information about the Libreoffice-commits mailing list