diff options
author | Hironobu Yamashita <h.y.acetaminophen@gmail.com> | 2022-08-29 13:52:14 +0000 |
---|---|---|
committer | Hironobu Yamashita <h.y.acetaminophen@gmail.com> | 2022-08-29 13:52:14 +0000 |
commit | 4c5fc2acc23b0715c5cc5aa4adc87c8b998a0cab (patch) | |
tree | a9d9e4ade07bf8a5b82c2a582885324300040c90 /Build/source/texk/dvisvgm/dvisvgm-src/src/XMLParser.hpp | |
parent | d6b263980d8d5e05e039587454b7d30c438ff05c (diff) |
dvisvgm 2.14
git-svn-id: svn://tug.org/texlive/trunk@64224 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/XMLParser.hpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/XMLParser.hpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLParser.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLParser.hpp new file mode 100644 index 00000000000..51f6a62544c --- /dev/null +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/XMLParser.hpp @@ -0,0 +1,58 @@ +/************************************************************************* +** XMLParser.hpp ** +** ** +** This file is part of dvisvgm -- a fast DVI to SVG converter ** +** Copyright (C) 2005-2022 Martin Gieseking <martin.gieseking@uos.de> ** +** ** +** This program is free software; you can redistribute it and/or ** +** modify it under the terms of the GNU General Public License as ** +** published by the Free Software Foundation; either version 3 of ** +** the License, or (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, but ** +** WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program; if not, see <http://www.gnu.org/licenses/>. ** +*************************************************************************/ + +#ifndef XMLPARSER_HPP +#define XMLPARSER_HPP + +#include <string> +#include "MessageException.hpp" +#include "SVGTree.hpp" + +struct XMLParserException : MessageException { + explicit XMLParserException (const std::string &msg) : MessageException(msg) {} +}; + +class XMLParser { + using AppendFunc = void (SVGTree::*)(std::unique_ptr<XMLNode>); + using PushFunc = void (SVGTree::*)(std::unique_ptr<SVGElement>); + using PopFunc = void (SVGTree::*)(); + using NameStack = std::vector<std::string>; + + public: + XMLParser (AppendFunc append, PushFunc push, PopFunc pop) + : _append(append), _pushContext(push), _popContext(pop) {} + + void parse (const std::string &xml, SVGTree &svgTree, bool finish=false); + void finish (SVGTree &svgTree); + + protected: + void openElement (const std::string &tag, SVGTree &svgTree); + void closeElement (const std::string &tag, SVGTree &svgTree); + + private: + AppendFunc _append; + PushFunc _pushContext; + PopFunc _popContext; + std::string _xmlbuf; + NameStack _nameStack; ///< names of nested elements still missing a closing tag + bool _error=false; +}; + +#endif |