summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pugixml.cpp37
-rw-r--r--src/pugixml.hpp30
2 files changed, 60 insertions, 7 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index c7ac5d1..382bf50 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -1621,6 +1621,7 @@ namespace pugi
return xml_node(); // Not found.
}
+#ifndef PUGIXML_NO_STL
std::string xml_node::path(char delimiter) const
{
std::string path;
@@ -1641,6 +1642,7 @@ namespace pugi
return path;
}
+#endif
xml_node xml_node::first_element_by_path(const char* path, char delimiter) const
{
@@ -1844,16 +1846,23 @@ namespace pugi
{
}
+#ifndef PUGIXML_NO_STL
xml_parser::xml_parser(std::istream& stream,unsigned int optmsk): _xmldoc(0), _optmsk(optmsk)
{
parse(stream, _optmsk);
}
+#endif
xml_parser::xml_parser(char* xmlstr,unsigned int optmsk): _xmldoc(0), _optmsk(optmsk)
{
parse(xmlstr, _optmsk);
}
+ xml_parser::xml_parser(const transfer_ownership_tag& tag, char* xmlstr,unsigned int optmsk): _xmldoc(0), _optmsk(optmsk), _buffer(0)
+ {
+ parse(tag, xmlstr, _optmsk);
+ }
+
xml_parser::~xml_parser()
{
xml_memory_block* current = _memory.next;
@@ -1888,6 +1897,7 @@ namespace pugi
return prev;
}
+#ifndef PUGIXML_NO_STL
void xml_parser::parse(std::istream& stream,unsigned int optmsk)
{
int length = 0, pos = stream.tellg();
@@ -1895,12 +1905,13 @@ namespace pugi
length = stream.tellg();
stream.seekg(pos, std::ios_base::beg);
- _buffer.resize(length + 1);
- stream.read(&_buffer[0], length);
+ _buffer = new char[length + 1];
+ stream.read(_buffer, length);
_buffer[length] = 0;
- parse(&_buffer[0],optmsk); // Parse the input string.
+ parse(_buffer, optmsk); // Parse the input string.
}
+#endif
char* xml_parser::parse(char* xmlstr,unsigned int optmsk)
{
@@ -1917,6 +1928,25 @@ namespace pugi
return parser.parse(xmlstr,_xmldoc,_optmsk); // Parse the input string.
}
+ char* xml_parser::parse(const transfer_ownership_tag&, char* xmlstr,unsigned int optmsk)
+ {
+ if(!xmlstr) return NULL;
+
+ delete[] _buffer;
+ _buffer = xmlstr;
+
+ xml_allocator alloc(&_memory);
+
+ _xmldoc = alloc.allocate<xml_node_struct>(node_document); // Allocate a new root.
+ _xmldoc->parent = _xmldoc; // Point to self.
+ if(optmsk != parse_noset) _optmsk = optmsk;
+
+ xml_parser_impl parser(alloc);
+
+ return parser.parse(xmlstr,_xmldoc,_optmsk); // Parse the input string.
+ }
+
+#ifndef PUGIXML_NO_STL
std::string utf8(const wchar_t* str)
{
std::string result;
@@ -1946,4 +1976,5 @@ namespace pugi
return result;
}
+#endif
}
diff --git a/src/pugixml.hpp b/src/pugixml.hpp
index 7c65ebe..e651b84 100644
--- a/src/pugixml.hpp
+++ b/src/pugixml.hpp
@@ -14,9 +14,10 @@
#ifndef HEADER_PUGIXML_HPP
#define HEADER_PUGIXML_HPP
-#include <vector>
-#include <string>
-#include <istream>
+#ifndef PUGIXML_NO_STL
+# include <string>
+# include <istream>
+#endif
/// The PugiXML Parser namespace.
namespace pugi
@@ -479,11 +480,13 @@ namespace pugi
char data[memory_block_size];
};
+ struct transfer_ownership_tag {};
+
/// Provides a high-level interface to the XML parser.
class xml_parser
{
private:
- std::vector<char> _buffer; ///< character buffer
+ char* _buffer; ///< character buffer
xml_memory_block _memory; ///< Memory block
@@ -504,11 +507,19 @@ namespace pugi
/// \see parse
xml_parser(char* xmlstr, unsigned int optmsk = parse_default);
+ /// Parse constructor that gains ownership.
+ /// \param xmlstr - readwrite string with xml data
+ /// \param optmsk - Options mask.
+ /// \see parse
+ xml_parser(const transfer_ownership_tag&, char* xmlstr, unsigned int optmsk = parse_default);
+
+#ifndef PUGIXML_NO_STL
/// Parse constructor.
/// \param stream - stream with xml data
/// \param optmsk - Options mask.
/// \see parse
xml_parser(std::istream& stream, unsigned int optmsk = parse_default);
+#endif
/// Dtor
~xml_parser();
@@ -528,10 +539,12 @@ namespace pugi
unsigned int options(unsigned int optmsk);
public:
+#ifndef PUGIXML_NO_STL
/// Parse the given XML stream
/// \param stream - stream with xml data
/// \param optmsk - Options mask.
void parse(std::istream& stream, unsigned int optmsk = parse_noset);
+#endif
/// Parse the given XML string in-situ.
/// \param xmlstr - readwrite string with xml data
@@ -539,15 +552,24 @@ namespace pugi
/// \return last position or NULL
/// \rem input string is zero-segmented
char* parse(char* xmlstr, unsigned int optmsk = parse_noset);
+
+ /// Parse the given XML string in-situ (gains ownership).
+ /// \param xmlstr - readwrite string with xml data
+ /// \param optmsk - Options mask.
+ /// \return last position or NULL
+ /// \rem input string is zero-segmented
+ char* parse(const transfer_ownership_tag&, char* xmlstr, unsigned int optmsk = parse_noset);
};
/// Utility functions for xml
+#ifndef PUGIXML_NO_STL
/// Convert utf16 to utf8
std::string utf8(const wchar_t* str);
/// Convert utf8 to utf16
std::wstring utf16(const char* str);
+#endif
}
/// Inline implementation