Bump version to 5.0-14
[LibreOffice.git] / svtools / source / svhtml / htmlsupp.cxx
blobb9109260177d98a6325f91479c841e265676164b
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 <comphelper/string.hxx>
23 #include <svtools/parhtml.hxx>
24 #include <svtools/htmltokn.h>
25 #include <svtools/htmlkywd.hxx>
26 #include <tools/urlobj.hxx>
28 // Table for converting option values into strings
29 static HTMLOptionEnum const aScriptLangOptEnums[] =
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 }
38 bool HTMLParser::ParseScriptOptions( OUString& rLangString, const OUString& rBaseURL,
39 HTMLScriptLanguage& rLang,
40 OUString& rSrc,
41 OUString& rLibrary,
42 OUString& rModule )
44 const HTMLOptions& aScriptOptions = GetOptions();
46 rLangString.clear();
47 rLang = HTML_SL_JAVASCRIPT;
48 rSrc.clear();
49 rLibrary.clear();
50 rModule.clear();
52 for( size_t i = aScriptOptions.size(); i; )
54 const HTMLOption& aOption = aScriptOptions[--i];
55 switch( aOption.GetToken() )
57 case HTML_O_LANGUAGE:
59 rLangString = aOption.GetString();
60 sal_uInt16 nLang;
61 if( aOption.GetEnum( nLang, aScriptLangOptEnums ) )
62 rLang = (HTMLScriptLanguage)nLang;
63 else
64 rLang = HTML_SL_UNKNOWN;
66 break;
68 case HTML_O_SRC:
69 rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() );
70 break;
71 case HTML_O_SDLIBRARY:
72 rLibrary = aOption.GetString();
73 break;
75 case HTML_O_SDMODULE:
76 rModule = aOption.GetString();
77 break;
81 return true;
84 void HTMLParser::RemoveSGMLComment( OUString &rString, bool bFull )
86 sal_Unicode c = 0;
87 while( !rString.isEmpty() &&
88 ( ' '==(c=rString[0]) || '\t'==c || '\r'==c || '\n'==c ) )
89 rString = rString.copy( 1, rString.getLength() - 1 );
91 while( !rString.isEmpty() &&
92 ( ' '==(c=rString[rString.getLength()-1])
93 || '\t'==c || '\r'==c || '\n'==c ) )
94 rString = rString.copy( 0, rString.getLength()-1 );
97 // remove SGML comments
98 if( rString.startsWith( "<!--" ) )
100 sal_Int32 nPos = 3;
101 if( bFull )
103 // the whole line
104 nPos = 4;
105 while( nPos < rString.getLength() &&
106 ( ( c = rString[nPos] ) != '\r' && c != '\n' ) )
107 ++nPos;
108 if( c == '\r' && nPos+1 < rString.getLength() &&
109 '\n' == rString[nPos+1] )
110 ++nPos;
111 else if( c != '\n' )
112 nPos = 3;
114 ++nPos;
115 rString = rString.copy( nPos, rString.getLength() - nPos );
118 if( rString.endsWith("-->") )
120 rString = rString.copy( 0, rString.getLength()-3 );
121 if( bFull )
123 // "//" or "'", maybe preceding CR/LF
124 rString = comphelper::string::stripEnd(rString, ' ');
125 sal_Int32 nDel = 0, nLen = rString.getLength();
126 if( nLen >= 2 &&
127 rString.endsWith("//") )
129 nDel = 2;
131 else if( nLen && '\'' == rString[nLen-1] )
133 nDel = 1;
135 if( nDel && nLen >= nDel+1 )
137 c = rString[nLen-(nDel+1)];
138 if( '\r'==c || '\n'==c )
140 nDel++;
141 if( '\n'==c && nLen >= nDel+1 &&
142 '\r'==rString[nLen-(nDel+1)] )
143 nDel++;
146 rString = rString.copy( 0, nLen-nDel );
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */