Added 0.5-compatible interfaces for compatibility

git-svn-id: http://pugixml.googlecode.com/svn/trunk@386 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
arseny.kapoulkine 2010-05-08 16:44:04 +00:00
parent 18819327e9
commit 021574a484
3 changed files with 120 additions and 4 deletions

View File

@ -4009,6 +4009,16 @@ namespace pugi
return load_buffer(contents, impl::strlen(contents) * sizeof(char_t), options, encoding); 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) xml_parse_result xml_document::load_file(const char* name, unsigned int options, encoding_t encoding)
{ {
destroy(); destroy();
@ -4205,6 +4215,11 @@ namespace pugi
return result; return result;
} }
std::wstring PUGIXML_FUNCTION as_utf16(const char* str)
{
return as_wide(str);
}
std::wstring PUGIXML_FUNCTION as_wide(const char* str) std::wstring PUGIXML_FUNCTION as_wide(const char* str)
{ {
const impl::char8_t* data = reinterpret_cast<const impl::char8_t*>(str); const impl::char8_t* data = reinterpret_cast<const impl::char8_t*>(str);

View File

@ -17,8 +17,6 @@
#include "pugiconfig.hpp" #include "pugiconfig.hpp"
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
#include <exception>
namespace std namespace std
{ {
struct bidirectional_iterator_tag; struct bidirectional_iterator_tag;
@ -38,6 +36,11 @@ namespace std
} }
#endif #endif
// Macro for deprecated features
#ifndef PUGIXML_DEPRECATED
# define PUGIXML_DEPRECATED(message)
#endif
// No XPath without STL // No XPath without STL
#ifdef PUGIXML_NO_STL #ifdef PUGIXML_NO_STL
# ifndef PUGIXML_NO_XPATH # ifndef PUGIXML_NO_XPATH
@ -45,6 +48,11 @@ namespace std
# endif # endif
#endif #endif
// Include exception header for XPath
#ifndef PUGIXML_NO_XPATH
# include <exception>
#endif
// If no API is defined, assume default // If no API is defined, assume default
#ifndef PUGIXML_API #ifndef PUGIXML_API
# define PUGIXML_API # define PUGIXML_API
@ -276,6 +284,8 @@ namespace pugi
* This flag is off by default. * This flag is off by default.
*/ */
const unsigned int format_write_bom = 0x02; 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. * 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 indent - indentation string
* \param flags - formatting flags * \param flags - formatting flags
* \param depth - starting depth (used for indentation) * \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; 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 indent - indentation string
* \param flags - formatting flags * \param flags - formatting flags
* \param depth - starting depth (used for indentation) * \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; 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 #endif
@ -1741,6 +1749,12 @@ namespace pugi
char data[memory_block_size]; 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 * 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); 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 * Load document from file
* *
@ -2191,6 +2229,14 @@ namespace pugi
*/ */
std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str); std::basic_string<char, std::char_traits<char>, std::allocator<char> > 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<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_utf16(const char* str);
/** /**
* Convert utf8 to wide string * Convert utf8 to wide string
* *

55
tests/test_deprecated.cpp Normal file
View File

@ -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
}