[Libreoffice-commits] .: sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Dec 10 10:11:39 PST 2010


 sc/source/core/tool/rangelst.cxx |   49 ++++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 8 deletions(-)

New commits:
commit 0ef30cc1f331e3c708807205ac4f59662a72b16a
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Dec 10 13:11:18 2010 -0500

    Use for_each to format string for range list.

diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index 7688974..971d910 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -48,6 +48,7 @@ using ::std::vector;
 using ::std::advance;
 using ::std::find_if;
 using ::std::for_each;
+using ::formula::FormulaGrammar;
 
 namespace {
 
@@ -121,6 +122,44 @@ private:
     size_t mnCellCount;
 };
 
+class FormatString : public ::std::unary_function<void, const ScRange*>
+{
+public:
+    FormatString(String& rStr, USHORT nFlags, ScDocument* pDoc, FormulaGrammar::AddressConvention eConv, sal_Unicode cDelim) :
+        mrStr(rStr),
+        mnFlags(nFlags),
+        mpDoc(pDoc),
+        meConv(eConv),
+        mcDelim(cDelim),
+        mbFirst(true) {}
+
+    FormatString(const FormatString& r) :
+        mrStr(r.mrStr),
+        mnFlags(r.mnFlags),
+        mpDoc(r.mpDoc),
+        meConv(r.meConv),
+        mcDelim(r.mcDelim),
+        mbFirst(r.mbFirst) {}
+
+    void operator() (const ScRange* p)
+    {
+        String aStr;
+        p->Format(aStr, mnFlags, mpDoc, meConv);
+        if (mbFirst)
+            mbFirst = false;
+        else
+            mrStr += mcDelim;
+        mrStr += aStr;
+    }
+private:
+    String& mrStr;
+    USHORT mnFlags;
+    ScDocument* mpDoc;
+    FormulaGrammar::AddressConvention meConv;
+    sal_Unicode mcDelim;
+    bool mbFirst;
+};
+
 }
 
 // === ScRangeList ====================================================
@@ -186,14 +225,8 @@ void ScRangeList::Format( String& rStr, USHORT nFlags, ScDocument* pDoc,
     if (!cDelimiter)
         cDelimiter = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
 
-    for ( size_t nIdx = 0, nCnt = maRanges.size(); nIdx < nCnt; ++nIdx )
-    {
-        String aStr;
-        at( nIdx )->Format( aStr, nFlags, pDoc, eConv );
-        if ( nIdx )
-            rStr += cDelimiter;
-        rStr += aStr;
-    }
+    FormatString func(rStr, nFlags, pDoc, eConv, cDelimiter);
+    for_each(maRanges.begin(), maRanges.end(), func);
 }
 
 


More information about the Libreoffice-commits mailing list