update credits
[LibreOffice.git] / svtools / source / svhtml / htmlsupp.cxx
blob3d90fecf30a33ca52be66d3d993f94d0769858bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
29 // Table for converting option values into strings
30 static HTMLOptionEnum const aScriptLangOptEnums[] =
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 }
39 bool HTMLParser::ParseScriptOptions( String& rLangString, const String& rBaseURL,
40 HTMLScriptLanguage& rLang,
41 String& rSrc,
42 String& rLibrary,
43 String& rModule )
45 const HTMLOptions& aScriptOptions = GetOptions();
47 rLangString.Erase();
48 rLang = HTML_SL_JAVASCRIPT;
49 rSrc.Erase();
50 rLibrary.Erase();
51 rModule.Erase();
53 for( size_t i = aScriptOptions.size(); i; )
55 const HTMLOption& aOption = aScriptOptions[--i];
56 switch( aOption.GetToken() )
58 case HTML_O_LANGUAGE:
60 rLangString = aOption.GetString();
61 sal_uInt16 nLang;
62 if( aOption.GetEnum( nLang, aScriptLangOptEnums ) )
63 rLang = (HTMLScriptLanguage)nLang;
64 else
65 rLang = HTML_SL_UNKNOWN;
67 break;
69 case HTML_O_SRC:
70 rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() );
71 break;
72 case HTML_O_SDLIBRARY:
73 rLibrary = aOption.GetString();
74 break;
76 case HTML_O_SDMODULE:
77 rModule = aOption.GetString();
78 break;
82 return true;
85 void HTMLParser::RemoveSGMLComment( String &rString, sal_Bool bFull )
87 sal_Unicode c = 0;
88 while( rString.Len() &&
89 ( ' '==(c=rString.GetChar(0)) || '\t'==c || '\r'==c || '\n'==c ) )
90 rString.Erase( 0, 1 );
92 while( rString.Len() &&
93 ( ' '==(c=rString.GetChar( rString.Len()-1))
94 || '\t'==c || '\r'==c || '\n'==c ) )
95 rString.Erase( rString.Len()-1 );
98 // remove SGML comments
99 if( rString.Len() >= 4 &&
100 rString.CompareToAscii( "<!--", 4 ) == COMPARE_EQUAL )
102 xub_StrLen nPos = 3;
103 if( bFull )
105 // the whole line
106 nPos = 4;
107 while( nPos < rString.Len() &&
108 ( ( c = rString.GetChar( nPos )) != '\r' && c != '\n' ) )
109 ++nPos;
110 if( c == '\r' && nPos+1 < rString.Len() &&
111 '\n' == rString.GetChar( nPos+1 ))
112 ++nPos;
113 else if( c != '\n' )
114 nPos = 3;
116 rString.Erase( 0, ++nPos );
119 if( rString.Len() >=3 &&
120 rString.Copy(rString.Len()-3).CompareToAscii("-->")
121 == COMPARE_EQUAL )
123 rString.Erase( rString.Len()-3 );
124 if( bFull )
126 // "//" or "'", maybe preceding CR/LF
127 rString = comphelper::string::stripEnd(rString, ' ');
128 xub_StrLen nDel = 0, nLen = rString.Len();
129 if( nLen >= 2 &&
130 rString.Copy(nLen-2).CompareToAscii("//") == COMPARE_EQUAL )
132 nDel = 2;
134 else if( nLen && '\'' == rString.GetChar(nLen-1) )
136 nDel = 1;
138 if( nDel && nLen >= nDel+1 )
140 c = rString.GetChar( nLen-(nDel+1) );
141 if( '\r'==c || '\n'==c )
143 nDel++;
144 if( '\n'==c && nLen >= nDel+1 &&
145 '\r'==rString.GetChar( nLen-(nDel+1) ) )
146 nDel++;
149 rString.Erase( nLen-nDel );
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */