diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /svtools/source/svhtml/htmlsupp.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'svtools/source/svhtml/htmlsupp.cxx')
-rw-r--r-- | svtools/source/svhtml/htmlsupp.cxx | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/svtools/source/svhtml/htmlsupp.cxx b/svtools/source/svhtml/htmlsupp.cxx new file mode 100644 index 0000000000..a418d61eb7 --- /dev/null +++ b/svtools/source/svhtml/htmlsupp.cxx @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <comphelper/string.hxx> +#include <svtools/parhtml.hxx> +#include <svtools/htmltokn.h> +#include <svtools/htmlkywd.hxx> +#include <tools/urlobj.hxx> + +// Table for converting option values into strings +HTMLOptionEnum<HTMLScriptLanguage> const aScriptLangOptEnums[] = +{ + { OOO_STRING_SVTOOLS_HTML_LG_starbasic, HTMLScriptLanguage::StarBasic }, + { OOO_STRING_SVTOOLS_HTML_LG_javascript, HTMLScriptLanguage::JavaScript }, + { OOO_STRING_SVTOOLS_HTML_LG_javascript11, HTMLScriptLanguage::JavaScript }, + { OOO_STRING_SVTOOLS_HTML_LG_livescript, HTMLScriptLanguage::JavaScript }, + { nullptr, HTMLScriptLanguage(0) } +}; + +void HTMLParser::ParseScriptOptions( OUString& rLangString, std::u16string_view rBaseURL, + HTMLScriptLanguage& rLang, + OUString& rSrc, + OUString& rLibrary, + OUString& rModule ) +{ + const HTMLOptions& aScriptOptions = GetOptions(); + + rLangString.clear(); + rLang = HTMLScriptLanguage::JavaScript; + rSrc.clear(); + rLibrary.clear(); + rModule.clear(); + + for( size_t i = aScriptOptions.size(); i; ) + { + const HTMLOption& aOption = aScriptOptions[--i]; + switch( aOption.GetToken() ) + { + case HtmlOptionId::LANGUAGE: + { + rLangString = aOption.GetString(); + HTMLScriptLanguage nLang; + if( aOption.GetEnum( nLang, aScriptLangOptEnums ) ) + rLang = nLang; + else + rLang = HTMLScriptLanguage::Unknown; + } + break; + + case HtmlOptionId::SRC: + rSrc = INetURLObject::GetAbsURL( rBaseURL, aOption.GetString() ); + break; + case HtmlOptionId::SDLIBRARY: + rLibrary = aOption.GetString(); + break; + + case HtmlOptionId::SDMODULE: + rModule = aOption.GetString(); + break; + default: break; + } + } +} + +void HTMLParser::RemoveSGMLComment( OUString &rString ) +{ + sal_Unicode c = 0; + sal_Int32 idx = 0; + while (idx < rString.getLength()) + { + c = rString[idx]; + if (!( c==' ' || c=='\t' || c=='\r' || c=='\n' ) ) + break; + idx++; + } + if (idx) + rString = rString.copy( idx ); + + idx = rString.getLength() - 1; + while (idx > 0) + // Can never get to 0 because that would mean the string contains only whitespace, and the first + // loop would already have removed all of those. + { + c = rString[idx]; + if (!( c==' ' || c=='\t' || c=='\r' || c=='\n' ) ) + break; + idx--; + } + if (idx != rString.getLength() - 1) + rString = rString.copy( 0, idx + 1 ); + + // remove SGML comments + if( rString.startsWith( "<!--" ) ) + { + // the whole line + sal_Int32 nPos = 4; + while( nPos < rString.getLength() ) + { + c = rString[nPos]; + if (c == '\r' || c == '\n') + break; + ++nPos; + } + if( c == '\r' && nPos+1 < rString.getLength() && + '\n' == rString[nPos+1] ) + ++nPos; + else if( c != '\n' ) + nPos = 3; + ++nPos; + rString = rString.copy( nPos ); + } + + if( !rString.endsWith("-->") ) + return; + + rString = rString.copy( 0, rString.getLength()-3 ); + // "//" or "'", maybe preceding CR/LF + rString = comphelper::string::stripEnd(rString, ' '); + sal_Int32 nDel = 0, nLen = rString.getLength(); + if( nLen >= 2 && + rString.endsWith("//") ) + { + nDel = 2; + } + else if( nLen && '\'' == rString[nLen-1] ) + { + nDel = 1; + } + if( nDel && nLen >= nDel+1 ) + { + c = rString[nLen-(nDel+1)]; + if( '\r'==c || '\n'==c ) + { + nDel++; + if( '\n'==c && nLen >= nDel+1 && + '\r'==rString[nLen-(nDel+1)] ) + nDel++; + } + } + rString = rString.copy( 0, nLen-nDel ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |