diff options
| -rw-r--r-- | src/pugixml.cpp | 15 | ||||
| -rw-r--r-- | src/pugixml.hpp | 54 | ||||
| -rw-r--r-- | tests/test_deprecated.cpp | 55 | 
3 files changed, 120 insertions, 4 deletions
| 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<const impl::char8_t*>(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 <exception>
 -
  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 <exception>
 +#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<char, std::char_traits<char> >& 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<wchar_t, std::char_traits<wchar_t> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const;
  	#endif
 @@ -1742,6 +1750,12 @@ namespace pugi  	};
  	/**
 +	 * 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
  	 */
  	enum xml_parse_status
 @@ -1852,6 +1866,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
  		 *
  		 * \param name - file name
 @@ -2197,6 +2235,14 @@ namespace pugi  	 * \param str - input UTF8 string
  	 * \return output wide string string
  	 */
 +	PUGIXML_DEPRECATED("Use as_wide instead") std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_utf16(const char* str);
 +
 +	/**
 +	 * Convert utf8 to wide string
 +	 *
 +	 * \param str - input UTF8 string
 +	 * \return output wide string string
 +	 */
  	std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
  #endif
 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 <string.h>
 +
 +#include "common.hpp"
 +
 +#include "writer_string.hpp"
 +
 +// format_write_bom_utf8 - it's now format_write_bom!
 +TEST_XML(document_save_bom_utf8, "<node/>")
 +{
 +	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<node />", 11));
 +}
 +
 +// parse - it's now load_buffer_inplace
 +TEST(document_parse)
 +{
 +	char text[] = "<node/>";
 +
 +	pugi::xml_document doc;
 +
 +	CHECK(doc.parse(text));
 +	CHECK_NODE(doc, STR("<node />"));
 +}
 +
 +// 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<char*>(alloc(strlen("<node/>") + 1));
 +	CHECK(text);
 +
 +	memcpy(text, "<node/>", strlen("<node/>") + 1);
 +
 +	pugi::xml_document doc;
 +
 +	CHECK(doc.parse(transfer_ownership_tag(), text));
 +	CHECK_NODE(doc, STR("<node />"));
 +}
 + 
 +// 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
 +}
 | 
