Avoid potential negative array index access to cached text.
[LibreOffice.git] / shell / inc / xml_parser.hxx
blobe07c860dd6995816d4c21b5cd0a08c482c010b2f
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 #ifndef INCLUDED_SHELL_INC_INTERNAL_XML_PARSER_HXX
21 #define INCLUDED_SHELL_INC_INTERNAL_XML_PARSER_HXX
23 #include <expat.h>
24 #include <stdexcept>
26 class xml_parser_exception final : public std::runtime_error
28 public:
29 xml_parser_exception(const std::string& error_msg)
30 : std::runtime_error(error_msg)
35 // Simple wrapper around expat, the xml parser library
36 // created by James Clark
38 class i_xml_parser_event_handler;
40 class xml_parser
42 public:
43 xml_parser();
45 ~xml_parser();
47 /** Parse a XML data stream
49 @param pXmlData
50 Pointer to a buffer containing the xml data
52 @param Length
53 Length of the buffer containing the xml data
55 @param IsFinal
56 Indicates whether these are the last xml data
57 of an xml document to parse. For very large
58 xml documents it may be useful to read and
59 parse the document partially.
61 @precond XmlData must not be null
63 @throws SaxException
64 If the used Sax parser returns an error. The SaxException
65 contains detailed information about the error. */
66 void parse(const char* XmlData, size_t Length, bool IsFinal);
68 /** Set a document handler
70 @descr A document handler implements the interface i_xml_parser_event_handler.
71 The document handler receive notifications of various events
72 from the sax parser for instance "start_document".
74 The client is responsible for the life time management of
75 the given document handler, that means the document handler
76 instance must exist until a new one was set or until the parser
77 no longer exist.
79 @param SaxDocumentHandler
80 The new document handler, may be null if not interested in
81 sax parser events.
83 @postcond currently used document handler == pSaxDocumentHandler */
84 void set_document_handler(i_xml_parser_event_handler* event_handler);
86 /** Returns the currently used document handler or null if
87 no document handler was set before. */
88 i_xml_parser_event_handler* get_document_handler() const { return document_handler_; }
90 private:
91 void init();
93 private:
94 i_xml_parser_event_handler* document_handler_;
95 XML_Parser xml_parser_;
97 private:
98 xml_parser(const xml_parser&) = delete;
99 xml_parser& operator=(const xml_parser&) = delete;
102 #endif
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */