[Libreoffice-commits] core.git: sw/inc sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Feb 26 00:31:57 PST 2015


 sw/inc/txatbase.hxx                 |    1 
 sw/source/core/docnode/nodedump.cxx |   44 ------------------------------------
 sw/source/core/txtnode/txatbase.cxx |   43 +++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 43 deletions(-)

New commits:
commit a4dbfa82fdf8e4473e342a358feff05df35260f7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Feb 26 09:30:59 2015 +0100

    Extract SwTxtAttr::dumpAsXml() from SwTxtNode
    
    Change-Id: I20914ec147b2af096bd40ec0e4da7567a44abaaa

diff --git a/sw/inc/txatbase.hxx b/sw/inc/txatbase.hxx
index f62ab1e..d8ccb02 100644
--- a/sw/inc/txatbase.hxx
+++ b/sw/inc/txatbase.hxx
@@ -119,6 +119,7 @@ public:
     inline const SwFmtRuby              &GetRuby() const;
     inline const SwFmtMeta              &GetMeta() const;
 
+    void dumpAsXml(struct _xmlTextWriter* pWriter) const;
 };
 
 class SwTxtAttrEnd : public virtual SwTxtAttr
diff --git a/sw/source/core/docnode/nodedump.cxx b/sw/source/core/docnode/nodedump.cxx
index edcf5ae..43f628a 100644
--- a/sw/source/core/docnode/nodedump.cxx
+++ b/sw/source/core/docnode/nodedump.cxx
@@ -283,49 +283,7 @@ void SwTxtNode::dumpAsXml( xmlTextWriterPtr w ) const
         writer.startElement("hints");
         const SwpHints& rHints = GetSwpHints();
         for (size_t i = 0; i < rHints.Count(); ++i)
-        {
-            writer.startElement("hint");
-            const SwTxtAttr* pHint = rHints.GetTextHint(i);
-
-            if (pHint->GetStart())
-                writer.writeFormatAttribute("start", TMP_FORMAT, pHint->GetStart());
-            if (pHint->End())
-                writer.writeFormatAttribute("end", TMP_FORMAT, *pHint->End());
-            writer.writeFormatAttribute("whichId", TMP_FORMAT, pHint->Which());
-
-            const char* pWhich = 0;
-            boost::optional<OString> oValue;
-            switch (pHint->Which())
-            {
-                case RES_TXTATR_AUTOFMT:
-                    pWhich = "autofmt";
-                    break;
-                case RES_TXTATR_ANNOTATION:
-                    pWhich = "annotation";
-                    break;
-                case RES_TXTATR_FLYCNT:
-                    pWhich = "fly content";
-                    break;
-                case RES_TXTATR_CHARFMT:
-                {
-                    pWhich = "character format";
-                    if (SwCharFmt* pCharFmt = pHint->GetCharFmt().GetCharFmt())
-                        oValue = "name: " + OUStringToOString(pCharFmt->GetName(), RTL_TEXTENCODING_UTF8);
-                    break;
-                }
-                default:
-                    break;
-            }
-            if (pWhich)
-                writer.writeFormatAttribute("which", "%s", BAD_CAST(pWhich));
-            if (oValue)
-                writer.writeFormatAttribute("value", "%s", BAD_CAST(oValue->getStr()));
-
-            if (pHint->Which() == RES_TXTATR_AUTOFMT)
-                pHint->GetAutoFmt().dumpAsXml(writer);
-
-            writer.endElement();
-        }
+            rHints.GetTextHint(i)->dumpAsXml(w);
         writer.endElement();
     }
     if (GetNumRule())
diff --git a/sw/source/core/txtnode/txatbase.cxx b/sw/source/core/txtnode/txatbase.cxx
index 7fe27c2..061cb25 100644
--- a/sw/source/core/txtnode/txatbase.cxx
+++ b/sw/source/core/txtnode/txatbase.cxx
@@ -17,6 +17,8 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <boost/optional.hpp>
+#include <libxml/xmlwriter.h>
 #include <svl/itempool.hxx>
 #include <txatbase.hxx>
 #include <fmtfld.hxx>
@@ -73,4 +75,45 @@ sal_Int32* SwTxtAttrEnd::GetEnd()
     return & m_nEnd;
 }
 
+void SwTxtAttr::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    xmlTextWriterStartElement(pWriter, BAD_CAST("swTxtAttr"));
+
+    xmlTextWriterWriteAttribute(pWriter, BAD_CAST("start"), BAD_CAST(OString::number(m_nStart).getStr()));
+    if (End())
+        xmlTextWriterWriteAttribute(pWriter, BAD_CAST("end"), BAD_CAST(OString::number(*End()).getStr()));
+    xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
+    const char* pWhich = 0;
+    boost::optional<OString> oValue;
+    switch (Which())
+    {
+    case RES_TXTATR_AUTOFMT:
+        pWhich = "autofmt";
+        break;
+    case RES_TXTATR_ANNOTATION:
+        pWhich = "annotation";
+        break;
+    case RES_TXTATR_FLYCNT:
+        pWhich = "fly content";
+        break;
+    case RES_TXTATR_CHARFMT:
+        {
+            pWhich = "character format";
+            if (SwCharFmt* pCharFmt = GetCharFmt().GetCharFmt())
+                oValue = "name: " + OUStringToOString(pCharFmt->GetName(), RTL_TEXTENCODING_UTF8);
+            break;
+        }
+    default:
+        break;
+    }
+    if (pWhich)
+        xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(pWhich));
+    if (oValue)
+        xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(oValue->getStr()));
+    if (Which() == RES_TXTATR_AUTOFMT)
+        GetAutoFmt().dumpAsXml(pWriter);
+
+    xmlTextWriterEndElement(pWriter);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list