LCOV - code coverage report
Current view: top level - svtools/source/svhtml - htmlsupp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 64 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 2 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <ctype.h>
      22             : #include <comphelper/string.hxx>
      23             : #include <svtools/parhtml.hxx>
      24             : #include <svtools/htmltokn.h>
      25             : #include <svtools/htmlkywd.hxx>
      26             : #include <tools/urlobj.hxx>
      27             : 
      28             : // Table for converting option values into strings
      29             : static HTMLOptionEnum const aScriptLangOptEnums[] =
      30             : {
      31             :     { OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTML_SL_STARBASIC   },
      32             :     { OOO_STRING_SVTOOLS_HTML_LG_javascript,    HTML_SL_JAVASCRIPT  },
      33             :     { OOO_STRING_SVTOOLS_HTML_LG_javascript11,HTML_SL_JAVASCRIPT    },
      34             :     { OOO_STRING_SVTOOLS_HTML_LG_livescript,    HTML_SL_JAVASCRIPT  },
      35             :     { 0,                    0                   }
      36             : };
      37             : 
      38           0 : bool HTMLParser::ParseScriptOptions( OUString& rLangString, const OUString& rBaseURL,
      39             :                                      HTMLScriptLanguage& rLang,
      40             :                                      OUString& rSrc,
      41             :                                      OUString& rLibrary,
      42             :                                      OUString& rModule )
      43             : {
      44           0 :     const HTMLOptions& aScriptOptions = GetOptions();
      45             : 
      46           0 :     rLangString.clear();
      47           0 :     rLang = HTML_SL_JAVASCRIPT;
      48           0 :     rSrc.clear();
      49           0 :     rLibrary.clear();
      50           0 :     rModule.clear();
      51             : 
      52           0 :     for( size_t i = aScriptOptions.size(); i; )
      53             :     {
      54           0 :         const HTMLOption& aOption = aScriptOptions[--i];
      55           0 :         switch( aOption.GetToken() )
      56             :         {
      57             :         case HTML_O_LANGUAGE:
      58             :             {
      59           0 :                 rLangString = aOption.GetString();
      60             :                 sal_uInt16 nLang;
      61           0 :                 if( aOption.GetEnum( nLang, aScriptLangOptEnums ) )
      62           0 :                     rLang = (HTMLScriptLanguage)nLang;
      63             :                 else
      64           0 :                     rLang = HTML_SL_UNKNOWN;
      65             :             }
      66           0 :             break;
      67             : 
      68             :         case HTML_O_SRC:
      69           0 :             rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() );
      70           0 :             break;
      71             :         case HTML_O_SDLIBRARY:
      72           0 :             rLibrary = aOption.GetString();
      73           0 :             break;
      74             : 
      75             :         case HTML_O_SDMODULE:
      76           0 :             rModule = aOption.GetString();
      77           0 :             break;
      78             :         }
      79             :     }
      80             : 
      81           0 :     return true;
      82             : }
      83             : 
      84           0 : void HTMLParser::RemoveSGMLComment( OUString &rString, bool bFull )
      85             : {
      86           0 :     sal_Unicode c = 0;
      87           0 :     while( !rString.isEmpty() &&
      88           0 :            ( ' '==(c=rString[0]) || '\t'==c || '\r'==c || '\n'==c ) )
      89           0 :         rString = rString.copy( 1, rString.getLength() - 1 );
      90             : 
      91           0 :     while( !rString.isEmpty() &&
      92           0 :            ( ' '==(c=rString[rString.getLength()-1])
      93           0 :            || '\t'==c || '\r'==c || '\n'==c ) )
      94           0 :         rString = rString.copy( 0, rString.getLength()-1 );
      95             : 
      96             : 
      97             :     // remove SGML comments
      98           0 :     if( rString.startsWith( "<!--" ) )
      99             :     {
     100           0 :         sal_Int32 nPos = 3;
     101           0 :         if( bFull )
     102             :         {
     103             :             // the whole line
     104           0 :             nPos = 4;
     105           0 :             while( nPos < rString.getLength() &&
     106           0 :                 ( ( c = rString[nPos] ) != '\r' && c != '\n' ) )
     107           0 :                 ++nPos;
     108           0 :             if( c == '\r' && nPos+1 < rString.getLength() &&
     109           0 :                 '\n' == rString[nPos+1] )
     110           0 :                 ++nPos;
     111           0 :             else if( c != '\n' )
     112           0 :                 nPos = 3;
     113             :         }
     114           0 :         ++nPos;
     115           0 :         rString = rString.copy( nPos, rString.getLength() - nPos );
     116             :     }
     117             : 
     118           0 :     if( rString.endsWith("-->") )
     119             :     {
     120           0 :         rString = rString.copy( 0, rString.getLength()-3 );
     121           0 :         if( bFull )
     122             :         {
     123             :             // "//" or "'", maybe preceding CR/LF
     124           0 :             rString = comphelper::string::stripEnd(rString, ' ');
     125           0 :             sal_Int32 nDel = 0, nLen = rString.getLength();
     126           0 :             if( nLen >= 2 &&
     127           0 :                 rString.endsWith("//") )
     128             :             {
     129           0 :                 nDel = 2;
     130             :             }
     131           0 :             else if( nLen && '\'' == rString[nLen-1] )
     132             :             {
     133           0 :                 nDel = 1;
     134             :             }
     135           0 :             if( nDel && nLen >= nDel+1 )
     136             :             {
     137           0 :                 c = rString[nLen-(nDel+1)];
     138           0 :                 if( '\r'==c || '\n'==c )
     139             :                 {
     140           0 :                     nDel++;
     141           0 :                     if( '\n'==c && nLen >= nDel+1 &&
     142           0 :                         '\r'==rString[nLen-(nDel+1)] )
     143           0 :                         nDel++;
     144             :                 }
     145             :             }
     146           0 :             rString = rString.copy( 0, nLen-nDel );
     147             :         }
     148             :     }
     149           0 : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11