LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/svhtml - htmlsupp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-12-17 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 <stdio.h>
      23             : #include <comphelper/string.hxx>
      24             : #include <svtools/parhtml.hxx>
      25             : #include <svtools/htmltokn.h>
      26             : #include <svtools/htmlkywd.hxx>
      27             : #include <tools/urlobj.hxx>
      28             : 
      29             : // Table for converting option values into strings
      30             : static HTMLOptionEnum const aScriptLangOptEnums[] =
      31             : {
      32             :     { OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTML_SL_STARBASIC   },
      33             :     { OOO_STRING_SVTOOLS_HTML_LG_javascript,    HTML_SL_JAVASCRIPT  },
      34             :     { OOO_STRING_SVTOOLS_HTML_LG_javascript11,HTML_SL_JAVASCRIPT    },
      35             :     { OOO_STRING_SVTOOLS_HTML_LG_livescript,    HTML_SL_JAVASCRIPT  },
      36             :     { 0,                    0                   }
      37             : };
      38             : 
      39           0 : bool HTMLParser::ParseScriptOptions( String& rLangString, const String& rBaseURL,
      40             :                                      HTMLScriptLanguage& rLang,
      41             :                                      String& rSrc,
      42             :                                      String& rLibrary,
      43             :                                      String& rModule )
      44             : {
      45           0 :     const HTMLOptions& aScriptOptions = GetOptions();
      46             : 
      47           0 :     rLangString.Erase();
      48           0 :     rLang = HTML_SL_JAVASCRIPT;
      49           0 :     rSrc.Erase();
      50           0 :     rLibrary.Erase();
      51           0 :     rModule.Erase();
      52             : 
      53           0 :     for( size_t i = aScriptOptions.size(); i; )
      54             :     {
      55           0 :         const HTMLOption& aOption = aScriptOptions[--i];
      56           0 :         switch( aOption.GetToken() )
      57             :         {
      58             :         case HTML_O_LANGUAGE:
      59             :             {
      60           0 :                 rLangString = aOption.GetString();
      61             :                 sal_uInt16 nLang;
      62           0 :                 if( aOption.GetEnum( nLang, aScriptLangOptEnums ) )
      63           0 :                     rLang = (HTMLScriptLanguage)nLang;
      64             :                 else
      65           0 :                     rLang = HTML_SL_UNKNOWN;
      66             :             }
      67           0 :             break;
      68             : 
      69             :         case HTML_O_SRC:
      70           0 :             rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() );
      71           0 :             break;
      72             :         case HTML_O_SDLIBRARY:
      73           0 :             rLibrary = aOption.GetString();
      74           0 :             break;
      75             : 
      76             :         case HTML_O_SDMODULE:
      77           0 :             rModule = aOption.GetString();
      78           0 :             break;
      79             :         }
      80             :     }
      81             : 
      82           0 :     return true;
      83             : }
      84             : 
      85           0 : void HTMLParser::RemoveSGMLComment( String &rString, sal_Bool bFull )
      86             : {
      87           0 :     sal_Unicode c = 0;
      88           0 :     while( rString.Len() &&
      89             :            ( ' '==(c=rString.GetChar(0)) || '\t'==c || '\r'==c || '\n'==c ) )
      90           0 :         rString.Erase( 0, 1 );
      91             : 
      92           0 :     while( rString.Len() &&
      93           0 :            ( ' '==(c=rString.GetChar( rString.Len()-1))
      94             :            || '\t'==c || '\r'==c || '\n'==c ) )
      95           0 :         rString.Erase( rString.Len()-1 );
      96             : 
      97             : 
      98             :     // remove SGML comments
      99           0 :     if( rString.Len() >= 4 &&
     100           0 :         rString.CompareToAscii( "<!--", 4 ) == COMPARE_EQUAL )
     101             :     {
     102           0 :         xub_StrLen nPos = 3;
     103           0 :         if( bFull )
     104             :         {
     105             :             // the whole line
     106           0 :             nPos = 4;
     107           0 :             while( nPos < rString.Len() &&
     108           0 :                 ( ( c = rString.GetChar( nPos )) != '\r' && c != '\n' ) )
     109           0 :                 ++nPos;
     110           0 :             if( c == '\r' && nPos+1 < rString.Len() &&
     111           0 :                 '\n' == rString.GetChar( nPos+1 ))
     112           0 :                 ++nPos;
     113           0 :             else if( c != '\n' )
     114           0 :                 nPos = 3;
     115             :         }
     116           0 :         rString.Erase( 0, ++nPos );
     117             :     }
     118             : 
     119           0 :     if( rString.Len() >=3 &&
     120           0 :         rString.Copy(rString.Len()-3).CompareToAscii("-->")
     121             :             == COMPARE_EQUAL )
     122             :     {
     123           0 :         rString.Erase( rString.Len()-3 );
     124           0 :         if( bFull )
     125             :         {
     126             :             // "//" or "'", maybe preceding CR/LF
     127           0 :             rString = comphelper::string::stripEnd(rString, ' ');
     128           0 :             xub_StrLen nDel = 0, nLen = rString.Len();
     129           0 :             if( nLen >= 2 &&
     130           0 :                 rString.Copy(nLen-2).CompareToAscii("//") == COMPARE_EQUAL )
     131             :             {
     132           0 :                 nDel = 2;
     133             :             }
     134           0 :             else if( nLen && '\'' == rString.GetChar(nLen-1) )
     135             :             {
     136           0 :                 nDel = 1;
     137             :             }
     138           0 :             if( nDel && nLen >= nDel+1 )
     139             :             {
     140           0 :                 c = rString.GetChar( nLen-(nDel+1) );
     141           0 :                 if( '\r'==c || '\n'==c )
     142             :                 {
     143           0 :                     nDel++;
     144           0 :                     if( '\n'==c && nLen >= nDel+1 &&
     145           0 :                         '\r'==rString.GetChar( nLen-(nDel+1) ) )
     146           0 :                         nDel++;
     147             :                 }
     148             :             }
     149           0 :             rString.Erase( nLen-nDel );
     150             :         }
     151             :     }
     152           0 : }
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10