diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-02-09 22:10:30 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-02-09 22:10:30 -0300 |
commit | 0b806ee0fc9097fa7bda7ac0109191c9c5e0a1ac (patch) | |
tree | 276c4d099e178eb67fbd14f61d77b05e3808e9e3 /core/io/xml_parser.h | |
parent | 0e49da1687bc8192ed210947da52c9e5c5f301bb (diff) | |
download | redot-engine-0b806ee0fc9097fa7bda7ac0109191c9c5e0a1ac.tar.gz |
GODOT IS OPEN SOURCE
Diffstat (limited to 'core/io/xml_parser.h')
-rw-r--r-- | core/io/xml_parser.h | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h new file mode 100644 index 0000000000..3025c041b3 --- /dev/null +++ b/core/io/xml_parser.h @@ -0,0 +1,123 @@ +/*************************************************************************/ +/* xml_parser.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef XML_PARSER_H +#define XML_PARSER_H + +#include "ustring.h" +#include "vector.h" +#include "os/file_access.h" +#include "reference.h" + +/* + Based on irrXML (see their zlib license). Added mainly for compatibility with their Collada loader. +*/ + +class XMLParser : public Reference { + + OBJ_TYPE( XMLParser, Reference ); +public: + //! Enumeration of all supported source text file formats + enum SourceFormat { + SOURCE_ASCII, + SOURCE_UTF8, + SOURCE_UTF16_BE, + SOURCE_UTF16_LE, + SOURCE_UTF32_BE, + SOURCE_UTF32_LE + }; + + enum NodeType { + NODE_NONE, + NODE_ELEMENT, + NODE_ELEMENT_END, + NODE_TEXT, + NODE_COMMENT, + NODE_CDATA, + NODE_UNKNOWN + }; + +private: + + char *data; + char *P; + int length; + void unescape(String& p_str); + Vector<String> special_characters; + String node_name; + bool node_empty; + NodeType node_type; + uint64_t node_offset; + + struct Attribute { + String name; + String value; + }; + + Vector<Attribute> attributes; + + String _replace_special_characters(const String& origstr); + bool _set_text(char* start, char* end); + void _parse_closing_xml_element(); + void _ignore_definition(); + bool _parse_cdata(); + void _parse_comment(); + void _parse_opening_xml_element(); + void _parse_current_node(); + + static void _bind_methods(); + +public: + + + Error read(); + NodeType get_node_type(); + String get_node_name() const; + String get_node_data() const; + uint64_t get_node_offset() const; + int get_attribute_count() const; + String get_attribute_name(int p_idx) const; + String get_attribute_value(int p_idx) const; + bool has_attribute(const String& p_name) const; + String get_attribute_value(const String& p_name) const; + String get_attribute_value_safe(const String& p_name) const; // do not print error if doesn't exist + bool is_empty() const; + int get_current_line() const; + + void skip_section(); + Error seek(uint64_t p_pos); + + Error open(const String& p_path); + void close(); + + XMLParser(); + ~XMLParser(); +}; + +#endif + |