LCOV - code coverage report
Current view: top level - l10ntools/source - helper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 77 0.0 %
Date: 2014-11-03 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "helper.hxx"
      11             : 
      12             : namespace helper {
      13             : 
      14           0 : OString escapeAll(
      15             :     const OString& rText, const OString& rUnEscaped, const OString& rEscaped )
      16             : {
      17             :     assert( rEscaped.getLength() == 2*rUnEscaped.getLength() );
      18           0 :     OStringBuffer sReturn;
      19           0 :     for ( sal_Int32 nIndex = 0; nIndex < rText.getLength(); ++nIndex )
      20             :     {
      21           0 :         sal_Int32 nUnEscapedOne = rUnEscaped.indexOf(rText[nIndex]);
      22           0 :         if( nUnEscapedOne != -1 )
      23             :         {
      24           0 :             sReturn.append(rEscaped.copy(nUnEscapedOne*2,2));
      25             :         }
      26             :         else
      27           0 :             sReturn.append(rText[nIndex]);
      28             :     }
      29           0 :     return sReturn.makeStringAndClear();
      30             : }
      31             : 
      32             : 
      33           0 : OString unEscapeAll(
      34             :     const OString& rText, const OString& rEscaped, const OString& rUnEscaped)
      35             : {
      36             :     assert( rEscaped.getLength() == 2*rUnEscaped.getLength() );
      37           0 :     OStringBuffer sReturn;
      38           0 :     const sal_Int32 nLength = rText.getLength();
      39           0 :     for ( sal_Int32 nIndex = 0; nIndex < nLength; ++nIndex )
      40             :     {
      41           0 :         if( rText[nIndex] == '\\' && nIndex+1 < nLength )
      42             :         {
      43           0 :             sal_Int32 nEscapedOne = rEscaped.indexOf(rText.copy(nIndex,2));
      44           0 :             if( nEscapedOne != -1 )
      45             :             {
      46           0 :                 sReturn.append(rUnEscaped[nEscapedOne/2]);
      47           0 :                 ++nIndex;
      48             :             }
      49             :             else
      50             :             {
      51           0 :                 sReturn.append(rText[nIndex]);
      52             :             }
      53             :         }
      54             :         else
      55           0 :             sReturn.append(rText[nIndex]);
      56             :     }
      57           0 :     return sReturn.makeStringAndClear();
      58             : }
      59             : 
      60             : 
      61           0 : OString QuotHTML(const OString &rString)
      62             : {
      63           0 :     OStringBuffer sReturn;
      64           0 :     for (sal_Int32 i = 0; i < rString.getLength(); ++i)
      65             :     {
      66           0 :         switch (rString[i])
      67             :         {
      68             :         case '<':
      69           0 :             sReturn.append("&lt;");
      70           0 :             break;
      71             :         case '>':
      72           0 :             sReturn.append("&gt;");
      73           0 :             break;
      74             :         case '"':
      75           0 :             sReturn.append("&quot;");
      76           0 :             break;
      77             :         case '\'':
      78           0 :             sReturn.append("&apos;");
      79           0 :             break;
      80             :         case '&':
      81           0 :             if (rString.match("&amp;", i))
      82           0 :                 sReturn.append('&');
      83             :             else
      84           0 :                 sReturn.append("&amp;");
      85           0 :             break;
      86             :         default:
      87           0 :             sReturn.append(rString[i]);
      88           0 :             break;
      89             :         }
      90             :     }
      91           0 :     return sReturn.makeStringAndClear();
      92             : }
      93             : 
      94           0 : OString UnQuotHTML( const OString& rString )
      95             : {
      96           0 :     OStringBuffer sReturn;
      97           0 :     for (sal_Int32 i = 0; i != rString.getLength();) {
      98           0 :         if (rString.match("&amp;", i)) {
      99           0 :             sReturn.append('&');
     100           0 :             i += RTL_CONSTASCII_LENGTH("&amp;");
     101           0 :         } else if (rString.match("&lt;", i)) {
     102           0 :             sReturn.append('<');
     103           0 :             i += RTL_CONSTASCII_LENGTH("&lt;");
     104           0 :         } else if (rString.match("&gt;", i)) {
     105           0 :             sReturn.append('>');
     106           0 :             i += RTL_CONSTASCII_LENGTH("&gt;");
     107           0 :         } else if (rString.match("&quot;", i)) {
     108           0 :             sReturn.append('"');
     109           0 :             i += RTL_CONSTASCII_LENGTH("&quot;");
     110           0 :         } else if (rString.match("&apos;", i)) {
     111           0 :             sReturn.append('\'');
     112           0 :             i += RTL_CONSTASCII_LENGTH("&apos;");
     113             :         } else {
     114           0 :             sReturn.append(rString[i]);
     115           0 :             ++i;
     116             :         }
     117             :     }
     118           0 :     return sReturn.makeStringAndClear();
     119             : }
     120             : 
     121           0 : bool isWellFormedXML( OString const & text )
     122             : {
     123             :     xmlDocPtr doc;
     124           0 :     OString content;
     125           0 :     bool result = true;
     126             : 
     127           0 :     content = "<root>";
     128           0 :     content += text;
     129           0 :     content += "</root>";
     130           0 :     doc = xmlParseMemory(content.getStr(),(int)content.getLength());
     131           0 :     if (doc == NULL) {
     132           0 :         result = false;
     133             :     }
     134           0 :     xmlFreeDoc(doc);
     135           0 :     xmlCleanupParser();
     136           0 :     return result;
     137             : }
     138             : 
     139             : //Convert xmlChar* to OString
     140           0 : OString xmlStrToOString( const xmlChar* pString )
     141             : {
     142           0 :     xmlChar* pTemp = xmlStrdup( pString );
     143             :     OString sResult =
     144           0 :         static_cast<OString>(reinterpret_cast<sal_Char*>( pTemp ));
     145           0 :     xmlFree( pTemp );
     146           0 :     return sResult;
     147             : }
     148             : 
     149             : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10