diff options
author | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-03-27 20:08:50 +0100 |
---|---|---|
committer | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-03-27 20:09:31 +0100 |
commit | 8e26b4783f1f47ff5d489e7df5869240eefd1071 (patch) | |
tree | 80c4c9899fb3b05fcadc845444b06e1e3221e1c2 /l10ntools/source/helper.cxx | |
parent | 239fb4cb41cb0d1ed42bf5cf8ecdabdca4a28a68 (diff) |
Refactor l10ntools
Delete unused functions.
Make Export class more encapsulated.
Move to local that functions which are used only in one file.
Common contans method which are used by all executables.
Helper contains methods belong to xml parsing.
Change-Id: I28773a2c7eea90da7df7f32720fd38de2cb661ac
Diffstat (limited to 'l10ntools/source/helper.cxx')
-rw-r--r-- | l10ntools/source/helper.cxx | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/l10ntools/source/helper.cxx b/l10ntools/source/helper.cxx new file mode 100644 index 000000000000..cbcf6d1572fb --- /dev/null +++ b/l10ntools/source/helper.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "helper.hxx" + +namespace helper { + +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.match("&", i)) + sReturn.append('&'); + else + sReturn.append("&"); + break; + } + } + return sReturn.makeStringAndClear(); +} + +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; +} + +//Convert xmlChar* to OString +OString xmlStrToOString( const xmlChar* pString ) +{ + xmlChar* pTemp = xmlStrdup( pString ); + OString sResult = + static_cast<OString>(reinterpret_cast<sal_Char*>( pTemp )); + xmlFree( pTemp ); + return sResult; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |