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 .
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
},
39 bool HTMLParser::ParseScriptOptions( String
& rLangString
, const String
& rBaseURL
,
40 HTMLScriptLanguage
& rLang
,
45 const HTMLOptions
& aScriptOptions
= GetOptions();
48 rLang
= HTML_SL_JAVASCRIPT
;
53 for( size_t i
= aScriptOptions
.size(); i
; )
55 const HTMLOption
& aOption
= aScriptOptions
[--i
];
56 switch( aOption
.GetToken() )
60 rLangString
= aOption
.GetString();
62 if( aOption
.GetEnum( nLang
, aScriptLangOptEnums
) )
63 rLang
= (HTMLScriptLanguage
)nLang
;
65 rLang
= HTML_SL_UNKNOWN
;
70 rSrc
= INetURLObject::GetAbsURL( rBaseURL
, aOption
.GetString() );
72 case HTML_O_SDLIBRARY
:
73 rLibrary
= aOption
.GetString();
77 rModule
= aOption
.GetString();
85 void HTMLParser::RemoveSGMLComment( String
&rString
, sal_Bool bFull
)
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
)
107 while( nPos
< rString
.Len() &&
108 ( ( c
= rString
.GetChar( nPos
)) != '\r' && c
!= '\n' ) )
110 if( c
== '\r' && nPos
+1 < rString
.Len() &&
111 '\n' == rString
.GetChar( nPos
+1 ))
116 rString
.Erase( 0, ++nPos
);
119 if( rString
.Len() >=3 &&
120 rString
.Copy(rString
.Len()-3).CompareToAscii("-->")
123 rString
.Erase( rString
.Len()-3 );
126 // "//" or "'", maybe preceding CR/LF
127 rString
= comphelper::string::stripEnd(rString
, ' ');
128 xub_StrLen nDel
= 0, nLen
= rString
.Len();
130 rString
.Copy(nLen
-2).CompareToAscii("//") == COMPARE_EQUAL
)
134 else if( nLen
&& '\'' == rString
.GetChar(nLen
-1) )
138 if( nDel
&& nLen
>= nDel
+1 )
140 c
= rString
.GetChar( nLen
-(nDel
+1) );
141 if( '\r'==c
|| '\n'==c
)
144 if( '\n'==c
&& nLen
>= nDel
+1 &&
145 '\r'==rString
.GetChar( nLen
-(nDel
+1) ) )
149 rString
.Erase( nLen
-nDel
);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */