[Libreoffice-commits] .: Branch 'feature/cmclayouttrans' - l10ntools/source

Caolán McNamara caolan at kemper.freedesktop.org
Tue Aug 7 08:15:36 PDT 2012


 l10ntools/source/uimerge.cxx |   50 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

New commits:
commit 8e4de959be7dfb7d33eb81cde1ab72209639aa99
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Aug 7 16:15:21 2012 +0100

    we need to escape xml on export
    
    Change-Id: I770e4e6b3b77892c3fe1ba1e55f3e6d5834dc6b7

diff --git a/l10ntools/source/uimerge.cxx b/l10ntools/source/uimerge.cxx
index cd7443e..7334b40 100644
--- a/l10ntools/source/uimerge.cxx
+++ b/l10ntools/source/uimerge.cxx
@@ -9,6 +9,8 @@
 
 #include <sal/main.h>
 
+#include <rtl/strbuf.hxx>
+
 #include <libxslt/transform.h>
 #include <libxslt/xslt.h>
 #include <libxslt/xsltutils.h>
@@ -166,6 +168,52 @@ int extractTranslations()
     return 0;
 }
 
+namespace
+{
+    rtl::OString QuotHTML(const rtl::OString &rString)
+    {
+        rtl::OStringBuffer sReturn;
+        for (sal_Int32 i = 0; i < rString.getLength(); ++i) {
+            switch (rString[i]) {
+            case '\\':
+                if (i < rString.getLength()) {
+                    switch (rString[i + 1]) {
+                    case '"':
+                    case '<':
+                    case '>':
+                    case '\\':
+                        ++i;
+                        break;
+                    }
+                }
+                // fall through
+            default:
+                sReturn.append(rString[i]);
+                break;
+
+            case '<':
+                sReturn.append("<");
+                break;
+
+            case '>':
+                sReturn.append(">");
+                break;
+
+            case '"':
+                sReturn.append(""");
+                break;
+
+            case '&':
+                if (rString.matchL(RTL_CONSTASCII_STRINGPARAM("&"), i))
+                    sReturn.append('&');
+                else
+                    sReturn.append(RTL_CONSTASCII_STRINGPARAM("&"));
+                break;
+            }
+        }
+        return sReturn.makeStringAndClear();
+    }
+}
 
 bool Merge(
     const rtl::OString &rSDFFile,
@@ -211,7 +259,7 @@ bool Merge(
             aDestination << " <e "
                 << "g=\"" << aI->second->sGID.getStr() << "\" "
                 << "i=\"" << aI->second->sLID.getStr() << "\">"
-                << sOut.getStr() << "</e>\n";
+                << QuotHTML(sOut).getStr() << "</e>\n";
         }
     }
 


More information about the Libreoffice-commits mailing list