tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / svtools / source / svhtml / htmlsupp.cxx
bloba418d61eb79c8a0b9cac08923ecb548b7f3a45c6
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 .
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,
38 OUString& rSrc,
39 OUString& rLibrary,
40 OUString& rModule )
42 const HTMLOptions& aScriptOptions = GetOptions();
44 rLangString.clear();
45 rLang = HTMLScriptLanguage::JavaScript;
46 rSrc.clear();
47 rLibrary.clear();
48 rModule.clear();
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 ) )
60 rLang = nLang;
61 else
62 rLang = HTMLScriptLanguage::Unknown;
64 break;
66 case HtmlOptionId::SRC:
67 rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() );
68 break;
69 case HtmlOptionId::SDLIBRARY:
70 rLibrary = aOption.GetString();
71 break;
73 case HtmlOptionId::SDMODULE:
74 rModule = aOption.GetString();
75 break;
76 default: break;
81 void HTMLParser::RemoveSGMLComment( OUString &rString )
83 sal_Unicode c = 0;
84 sal_Int32 idx = 0;
85 while (idx < rString.getLength())
87 c = rString[idx];
88 if (!( c==' ' || c=='\t' || c=='\r' || c=='\n' ) )
89 break;
90 idx++;
92 if (idx)
93 rString = rString.copy( idx );
95 idx = rString.getLength() - 1;
96 while (idx > 0)
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.
100 c = rString[idx];
101 if (!( c==' ' || c=='\t' || c=='\r' || c=='\n' ) )
102 break;
103 idx--;
105 if (idx != rString.getLength() - 1)
106 rString = rString.copy( 0, idx + 1 );
108 // remove SGML comments
109 if( rString.startsWith( "<!--" ) )
111 // the whole line
112 sal_Int32 nPos = 4;
113 while( nPos < rString.getLength() )
115 c = rString[nPos];
116 if (c == '\r' || c == '\n')
117 break;
118 ++nPos;
120 if( c == '\r' && nPos+1 < rString.getLength() &&
121 '\n' == rString[nPos+1] )
122 ++nPos;
123 else if( c != '\n' )
124 nPos = 3;
125 ++nPos;
126 rString = rString.copy( nPos );
129 if( !rString.endsWith("-->") )
130 return;
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();
136 if( nLen >= 2 &&
137 rString.endsWith("//") )
139 nDel = 2;
141 else if( nLen && '\'' == rString[nLen-1] )
143 nDel = 1;
145 if( nDel && nLen >= nDel+1 )
147 c = rString[nLen-(nDel+1)];
148 if( '\r'==c || '\n'==c )
150 nDel++;
151 if( '\n'==c && nLen >= nDel+1 &&
152 '\r'==rString[nLen-(nDel+1)] )
153 nDel++;
156 rString = rString.copy( 0, nLen-nDel );
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */