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 .
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
},
38 bool HTMLParser::ParseScriptOptions( OUString
& rLangString
, const OUString
& rBaseURL
,
39 HTMLScriptLanguage
& rLang
,
44 const HTMLOptions
& aScriptOptions
= GetOptions();
47 rLang
= HTML_SL_JAVASCRIPT
;
52 for( size_t i
= aScriptOptions
.size(); i
; )
54 const HTMLOption
& aOption
= aScriptOptions
[--i
];
55 switch( aOption
.GetToken() )
59 rLangString
= aOption
.GetString();
61 if( aOption
.GetEnum( nLang
, aScriptLangOptEnums
) )
62 rLang
= (HTMLScriptLanguage
)nLang
;
64 rLang
= HTML_SL_UNKNOWN
;
69 rSrc
= INetURLObject::GetAbsURL( rBaseURL
, aOption
.GetString() );
71 case HTML_O_SDLIBRARY
:
72 rLibrary
= aOption
.GetString();
76 rModule
= aOption
.GetString();
84 void HTMLParser::RemoveSGMLComment( OUString
&rString
, bool bFull
)
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( "<!--" ) )
105 while( nPos
< rString
.getLength() &&
106 ( ( c
= rString
[nPos
] ) != '\r' && c
!= '\n' ) )
108 if( c
== '\r' && nPos
+1 < rString
.getLength() &&
109 '\n' == rString
[nPos
+1] )
115 rString
= rString
.copy( nPos
, rString
.getLength() - nPos
);
118 if( rString
.endsWith("-->") )
120 rString
= rString
.copy( 0, rString
.getLength()-3 );
123 // "//" or "'", maybe preceding CR/LF
124 rString
= comphelper::string::stripEnd(rString
, ' ');
125 sal_Int32 nDel
= 0, nLen
= rString
.getLength();
127 rString
.endsWith("//") )
131 else if( nLen
&& '\'' == rString
[nLen
-1] )
135 if( nDel
&& nLen
>= nDel
+1 )
137 c
= rString
[nLen
-(nDel
+1)];
138 if( '\r'==c
|| '\n'==c
)
141 if( '\n'==c
&& nLen
>= nDel
+1 &&
142 '\r'==rString
[nLen
-(nDel
+1)] )
146 rString
= rString
.copy( 0, nLen
-nDel
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */