diff options
Diffstat (limited to 'l10ntools/source/helper.hxx')
-rw-r--r-- | l10ntools/source/helper.hxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx index cc33b71ff8ac..1d268dd1c0f7 100644 --- a/l10ntools/source/helper.hxx +++ b/l10ntools/source/helper.hxx @@ -35,8 +35,11 @@ #include <algorithm> #include <cassert> +#include <libxml/parser.h> + #include "rtl/string.hxx" #include "rtl/ustring.hxx" +#include "rtl/strbuf.hxx" #include "sal/types.h" namespace helper { @@ -100,6 +103,69 @@ 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; + OString content; + bool result = true; + + content = "<root>"; + content += text; + content += "</root>"; + doc = xmlParseMemory(content.getStr(),(int)content.getLength()); + if (doc == NULL) { + result = false; + } + xmlFreeDoc(doc); + xmlCleanupParser(); + return result; +} + + template< typename T > inline T abbreviate( T const & text, sal_Int32 start, sal_Int32 length) { |