diff options
author | Andras Timar <atimar@suse.com> | 2012-11-13 21:55:18 +0100 |
---|---|---|
committer | Andras Timar <atimar@suse.com> | 2012-11-13 21:55:18 +0100 |
commit | 6cfa7552eebf69daab1ed3acc2a9954d52f00aad (patch) | |
tree | 3c2be7c64fdb95b8043d167fe7b2781f6937324c /l10ntools | |
parent | 0a7189a3b2d8fc78e9b3ce1b5fff2622557258a5 (diff) |
fix XML tag check in help and readme translations
Change-Id: I88a3ad382df41da96fcab38c3c06d5871228e082
Diffstat (limited to 'l10ntools')
-rw-r--r-- | l10ntools/source/helper.hxx | 46 | ||||
-rw-r--r-- | l10ntools/source/helpmerge.cxx | 2 | ||||
-rw-r--r-- | l10ntools/source/xrmmerge.cxx | 4 |
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("<"); + 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(); +} + 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 " ); |