summaryrefslogtreecommitdiff
path: root/l10ntools
diff options
context:
space:
mode:
authorAndras Timar <atimar@suse.com>2012-11-13 21:55:18 +0100
committerAndras Timar <atimar@suse.com>2012-11-13 21:55:18 +0100
commit6cfa7552eebf69daab1ed3acc2a9954d52f00aad (patch)
tree3c2be7c64fdb95b8043d167fe7b2781f6937324c /l10ntools
parent0a7189a3b2d8fc78e9b3ce1b5fff2622557258a5 (diff)
fix XML tag check in help and readme translations
Change-Id: I88a3ad382df41da96fcab38c3c06d5871228e082
Diffstat (limited to 'l10ntools')
-rw-r--r--l10ntools/source/helper.hxx46
-rw-r--r--l10ntools/source/helpmerge.cxx2
-rw-r--r--l10ntools/source/xrmmerge.cxx4
3 files changed, 49 insertions, 3 deletions
diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx
index 1e28aa6c4d50..1d268dd1c0f7 100644
--- a/l10ntools/source/helper.hxx
+++ b/l10ntools/source/helper.hxx
@@ -39,6 +39,7 @@
#include "rtl/string.hxx"
#include "rtl/ustring.hxx"
+#include "rtl/strbuf.hxx"
#include "sal/types.h"
namespace helper {
@@ -102,6 +103,50 @@ inline sal_Int32 indexOfAnyAsciiL(
return -1;
}
+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("&lt;");
+ break;
+
+ case '>':
+ sReturn.append("&gt;");
+ break;
+
+ case '"':
+ sReturn.append("&quot;");
+ break;
+
+ case '&':
+ if (rString.matchL(RTL_CONSTASCII_STRINGPARAM("&amp;"), i))
+ sReturn.append('&');
+ else
+ sReturn.append(RTL_CONSTASCII_STRINGPARAM("&amp;"));
+ break;
+ }
+ }
+ return sReturn.makeStringAndClear();
+}
+
inline bool isWellFormedXML( OString const & text )
{
xmlDocPtr doc;
@@ -120,6 +165,7 @@ inline bool isWellFormedXML( OString const & text )
return result;
}
+
template< typename T > inline T abbreviate(
T const & text, sal_Int32 start, sal_Int32 length)
{
diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx
index aab255f75a05..8764935ced2c 100644
--- a/l10ntools/source/helpmerge.cxx
+++ b/l10ntools/source/helpmerge.cxx
@@ -380,7 +380,7 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const rtl::OString& sCur ,
nPreSpaces++;
pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true );
OUString sNewdata;
- if (helper::isWellFormedXML(sNewText))
+ if (helper::isWellFormedXML(helper::QuotHTML(sNewText)))
{
sNewdata = sSourceText.copy(0,nPreSpaces) +
rtl::OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8);
diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx
index b4868f5f8623..5b562ea7f627 100644
--- a/l10ntools/source/xrmmerge.cxx
+++ b/l10ntools/source/xrmmerge.cxx
@@ -609,7 +609,6 @@ void XRMResMerge::WorkOnText(
sContent, STRING_TYP_TEXT, sLang )) &&
( sContent != "-" ) && !sContent.isEmpty() &&
helper::isWellFormedXML( sContent ))
-
{
rText = sContent;
ConvertStringToXMLFormat( rText );
@@ -645,7 +644,8 @@ void XRMResMerge::EndOfText(
if (!sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")) &&
( pEntrys->GetText(
sContent, STRING_TYP_TEXT, sCur, sal_True )) &&
- ( sContent != "-" ) && !sContent.isEmpty())
+ ( sContent != "-" ) && !sContent.isEmpty() &&
+ helper::isWellFormedXML( sContent ))
{
rtl::OString sText( sContent );
rtl::OString sAdditionalLine( "\n " );