From 021574a48430b6cc5589a76e7d02b1fc6a25849d Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sat, 8 May 2010 16:44:04 +0000 Subject: Added 0.5-compatible interfaces for compatibility git-svn-id: http://pugixml.googlecode.com/svn/trunk@386 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 15 +++++++++++++ src/pugixml.hpp | 54 ++++++++++++++++++++++++++++++++++++++++++---- tests/test_deprecated.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 tests/test_deprecated.cpp diff --git a/src/pugixml.cpp b/src/pugixml.cpp index b3f2c2c..615d7d4 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4009,6 +4009,16 @@ namespace pugi return load_buffer(contents, impl::strlen(contents) * sizeof(char_t), options, encoding); } + xml_parse_result xml_document::parse(char* xmlstr, unsigned int options) + { + return load_buffer_inplace(xmlstr, strlen(xmlstr), options, encoding_utf8); + } + + xml_parse_result xml_document::parse(const transfer_ownership_tag&, char* xmlstr, unsigned int options) + { + return load_buffer_inplace_own(xmlstr, strlen(xmlstr), options, encoding_utf8); + } + xml_parse_result xml_document::load_file(const char* name, unsigned int options, encoding_t encoding) { destroy(); @@ -4205,6 +4215,11 @@ namespace pugi return result; } + std::wstring PUGIXML_FUNCTION as_utf16(const char* str) + { + return as_wide(str); + } + std::wstring PUGIXML_FUNCTION as_wide(const char* str) { const impl::char8_t* data = reinterpret_cast(str); diff --git a/src/pugixml.hpp b/src/pugixml.hpp index ccc9f6f..86798e3 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -17,8 +17,6 @@ #include "pugiconfig.hpp" #ifndef PUGIXML_NO_STL -#include - namespace std { struct bidirectional_iterator_tag; @@ -38,6 +36,11 @@ namespace std } #endif +// Macro for deprecated features +#ifndef PUGIXML_DEPRECATED +# define PUGIXML_DEPRECATED(message) +#endif + // No XPath without STL #ifdef PUGIXML_NO_STL # ifndef PUGIXML_NO_XPATH @@ -45,6 +48,11 @@ namespace std # endif #endif +// Include exception header for XPath +#ifndef PUGIXML_NO_XPATH +# include +#endif + // If no API is defined, assume default #ifndef PUGIXML_API # define PUGIXML_API @@ -276,6 +284,8 @@ namespace pugi * This flag is off by default. */ const unsigned int format_write_bom = 0x02; + + PUGIXML_DEPRECATED("Use format_write_bom instead") const unsigned int format_write_bom_utf8 = format_write_bom; /** * If this flag is on, no indentation is performed and no line breaks are written to output file. @@ -1430,7 +1440,6 @@ namespace pugi * \param indent - indentation string * \param flags - formatting flags * \param depth - starting depth (used for indentation) - * \deprecated Use print() with xml_writer_stream instead */ void print(std::basic_ostream >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, encoding_t encoding = encoding_auto, unsigned int depth = 0) const; @@ -1441,7 +1450,6 @@ namespace pugi * \param indent - indentation string * \param flags - formatting flags * \param depth - starting depth (used for indentation) - * \deprecated Use print() with xml_writer_stream instead */ void print(std::basic_ostream >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const; #endif @@ -1741,6 +1749,12 @@ namespace pugi char data[memory_block_size]; }; + /** + * Struct used to distinguish parsing with ownership transfer from parsing without it. + * \see xml_document::parse + */ + PUGIXML_DEPRECATED("Use xml_document::load_buffer_inplace_own instead") struct transfer_ownership_tag {}; + /** * Parsing status enumeration, returned as part of xml_parse_result struct */ @@ -1851,6 +1865,30 @@ namespace pugi */ xml_parse_result load(const char_t* contents, unsigned int options = parse_default); + /** + * Parse the given XML string in-situ. + * The string is modified; you should ensure that string data will persist throughout the + * document's lifetime. Although, document does not gain ownership over the string, so you + * should free the memory occupied by it manually. + * + * \param xmlstr - readwrite string with xml data + * \param options - parsing options + * \return parsing result + */ + PUGIXML_DEPRECATED("Use xml_document::load_buffer_inplace instead") xml_parse_result parse(char* xmlstr, unsigned int options = parse_default); + + /** + * Parse the given XML string in-situ (gains ownership). + * The string is modified; document gains ownership over the string, so you don't have to worry + * about it's lifetime. + * Call example: doc.parse(transfer_ownership_tag(), string, options); + * + * \param xmlstr - readwrite string with xml data + * \param options - parsing options + * \return parsing result + */ + PUGIXML_DEPRECATED("Use xml_document::load_buffer_inplace_own instead") xml_parse_result parse(const transfer_ownership_tag&, char* xmlstr, unsigned int options = parse_default); + /** * Load document from file * @@ -2191,6 +2229,14 @@ namespace pugi */ std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf8(const wchar_t* str); + /** + * Convert utf8 to wide string + * + * \param str - input UTF8 string + * \return output wide string string + */ + PUGIXML_DEPRECATED("Use as_wide instead") std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf16(const char* str); + /** * Convert utf8 to wide string * diff --git a/tests/test_deprecated.cpp b/tests/test_deprecated.cpp new file mode 100644 index 0000000..e251876 --- /dev/null +++ b/tests/test_deprecated.cpp @@ -0,0 +1,55 @@ +// This file includes all tests for deprecated functionality; this is going away in the next release! + +#include + +#include "common.hpp" + +#include "writer_string.hpp" + +// format_write_bom_utf8 - it's now format_write_bom! +TEST_XML(document_save_bom_utf8, "") +{ + xml_writer_string writer; + + CHECK(test_save_narrow(doc, pugi::format_no_declaration | pugi::format_raw | pugi::format_write_bom_utf8, encoding_utf8, "\xef\xbb\xbf", 11)); +} + +// parse - it's now load_buffer_inplace +TEST(document_parse) +{ + char text[] = ""; + + pugi::xml_document doc; + + CHECK(doc.parse(text)); + CHECK_NODE(doc, STR("")); +} + +// parse with transfer_ownership_tag attribute - it's now load_buffer_inplace_own +TEST(document_parse_transfer_ownership) +{ + allocation_function alloc = get_memory_allocation_function(); + + char* text = static_cast(alloc(strlen("") + 1)); + CHECK(text); + + memcpy(text, "", strlen("") + 1); + + pugi::xml_document doc; + + CHECK(doc.parse(transfer_ownership_tag(), text)); + CHECK_NODE(doc, STR("")); +} + +// as_utf16 - it's now as_wide +TEST(as_utf16) +{ + CHECK(as_utf16("") == L""); + + // valid 1-byte, 2-byte and 3-byte inputs +#ifdef U_LITERALS + CHECK(as_utf16("?\xd0\x80\xe2\x80\xbd") == L"?\u0400\u203D"); +#else + CHECK(as_utf16("?\xd0\x80\xe2\x80\xbd") == L"?\x0400\x203D"); +#endif +} -- cgit v1.2.3