1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <comphelper/string.hxx>
21 #include <svtools/parhtml.hxx>
22 #include <svtools/htmltokn.h>
23 #include <svtools/htmlkywd.hxx>
24 #include <tools/urlobj.hxx>
26 // Table for converting option values into strings
27 HTMLOptionEnum
<HTMLScriptLanguage
> const aScriptLangOptEnums
[] =
29 { OOO_STRING_SVTOOLS_HTML_LG_starbasic
, HTMLScriptLanguage::StarBasic
},
30 { OOO_STRING_SVTOOLS_HTML_LG_javascript
, HTMLScriptLanguage::JavaScript
},
31 { OOO_STRING_SVTOOLS_HTML_LG_javascript11
, HTMLScriptLanguage::JavaScript
},
32 { OOO_STRING_SVTOOLS_HTML_LG_livescript
, HTMLScriptLanguage::JavaScript
},
33 { nullptr, HTMLScriptLanguage(0) }
36 void HTMLParser::ParseScriptOptions( OUString
& rLangString
, std::u16string_view rBaseURL
,
37 HTMLScriptLanguage
& rLang
,
42 const HTMLOptions
& aScriptOptions
= GetOptions();
45 rLang
= HTMLScriptLanguage::JavaScript
;
50 for( size_t i
= aScriptOptions
.size(); i
; )
52 const HTMLOption
& aOption
= aScriptOptions
[--i
];
53 switch( aOption
.GetToken() )
55 case HtmlOptionId::LANGUAGE
:
57 rLangString
= aOption
.GetString();
58 HTMLScriptLanguage nLang
;
59 if( aOption
.GetEnum( nLang
, aScriptLangOptEnums
) )
62 rLang
= HTMLScriptLanguage::Unknown
;
66 case HtmlOptionId::SRC
:
67 rSrc
= INetURLObject::GetAbsURL( rBaseURL
, aOption
.GetString() );
69 case HtmlOptionId::SDLIBRARY
:
70 rLibrary
= aOption
.GetString();
73 case HtmlOptionId::SDMODULE
:
74 rModule
= aOption
.GetString();
81 void HTMLParser::RemoveSGMLComment( OUString
&rString
)
85 while (idx
< rString
.getLength())
88 if (!( c
==' ' || c
=='\t' || c
=='\r' || c
=='\n' ) )
93 rString
= rString
.copy( idx
);
95 idx
= rString
.getLength() - 1;
97 // Can never get to 0 because that would mean the string contains only whitespace, and the first
98 // loop would already have removed all of those.
101 if (!( c
==' ' || c
=='\t' || c
=='\r' || c
=='\n' ) )
105 if (idx
!= rString
.getLength() - 1)
106 rString
= rString
.copy( 0, idx
+ 1 );
108 // remove SGML comments
109 if( rString
.startsWith( "<!--" ) )
113 while( nPos
< rString
.getLength() )
116 if (c
== '\r' || c
== '\n')
120 if( c
== '\r' && nPos
+1 < rString
.getLength() &&
121 '\n' == rString
[nPos
+1] )
126 rString
= rString
.copy( nPos
);
129 if( !rString
.endsWith("-->") )
132 rString
= rString
.copy( 0, rString
.getLength()-3 );
133 // "//" or "'", maybe preceding CR/LF
134 rString
= comphelper::string::stripEnd(rString
, ' ');
135 sal_Int32 nDel
= 0, nLen
= rString
.getLength();
137 rString
.endsWith("//") )
141 else if( nLen
&& '\'' == rString
[nLen
-1] )
145 if( nDel
&& nLen
>= nDel
+1 )
147 c
= rString
[nLen
-(nDel
+1)];
148 if( '\r'==c
|| '\n'==c
)
151 if( '\n'==c
&& nLen
>= nDel
+1 &&
152 '\r'==rString
[nLen
-(nDel
+1)] )
156 rString
= rString
.copy( 0, nLen
-nDel
);
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */