update XMLStorage to the current version, compatible to VS2008 and GCC@Linux

svn path=/trunk/; revision=39084
This commit is contained in:
Martin Fuchs 2009-01-25 11:20:47 +00:00
parent a00125aff1
commit 706b0df927
3 changed files with 103 additions and 43 deletions

View file

@ -2,7 +2,7 @@
//
// XML storage C++ classes version 1.3
//
// Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <martin-fuchs@gmx.net>
// Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009 Martin Fuchs <martin-fuchs@gmx.net>
//
/// \file xmlstorage.cpp
@ -37,12 +37,13 @@
*/
#include <precomp.h>
#ifndef XS_NO_COMMENT
#define XS_NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files
#define XS_NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files to enable static linking
#endif
//#include "xmlstorage.h"
#include <precomp.h>
namespace XMLStorage {
@ -280,15 +281,17 @@ XMLNode* XMLNode::create_relative(const XPath& xpath)
XMLNode* node = this;
for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
XMLNode* child = it->find(this);
XMLNode* child = it->find(node);
if (!child) {
child = new XMLNode(it->_child_name);
add_child(child);
node->add_child(child);
if (!it->_attr_name.empty())
(*this)[it->_attr_name] = it->_attr_value;
}
node = child;
}
return node;
@ -374,7 +377,7 @@ std::string EncodeXMLString(const XS_String& str, bool cdata)
if (cdata) {
// encode the whole string in a CDATA section
std::string ret = "<![CDATA[";
std::string ret = CDATA_START;
#ifdef XS_STRING_UTF8
ret += str;
@ -382,7 +385,7 @@ std::string EncodeXMLString(const XS_String& str, bool cdata)
ret += get_utf8(str);
#endif
ret += "]]>";
ret += CDATA_END;
return ret;
} else if (l <= BUFFER_LEN) {
@ -504,7 +507,7 @@ XS_String DecodeXMLString(const std::string& str)
} else //@@ maybe decode "&#xx;" special characters
*o++ = *p;
} else if (*p=='<' && !XS_nicmp(p+1,XS_TEXT("![CDATA["),8)) {
LPCXSSTR e = XS_strstr(p+9, XS_TEXT("]]>"));
LPCXSSTR e = XS_strstr(p+9, XS_TEXT(CDATA_END));
if (e) {
p += 9;
size_t l = e - p;
@ -532,7 +535,7 @@ void XMLNode::original_write_worker(std::ostream& out) const
out << '>';
if (_cdata_content)
out << EncodeXMLString(DecodeXMLString(_content), true);
out << CDATA_START << _content << CDATA_END;
else
out << _content;
@ -632,7 +635,7 @@ void XMLNode::smart_write_worker(std::ostream& out, const XMLFormat& format, int
out << '>';
if (_cdata_content)
out << EncodeXMLString(DecodeXMLString(_content), true);
out << CDATA_START << _content << CDATA_END;
else if (!*content)
out << format._endl;
else
@ -897,7 +900,7 @@ void XMLReaderBase::EndElementHandler()
const char* e = s + _content.length();
const char* p;
if (!strncmp(s,"<![CDATA[",9) && !strncmp(e-3,"]]>",3)) {
if (!strncmp(s,CDATA_START,9) && !strncmp(e-3,CDATA_END,3)) {
s += 9;
p = (e-=3);

View file

@ -2,7 +2,7 @@
//
// XML storage C++ classes version 1.3
//
// Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <martin-fuchs@gmx.net>
// Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009 Martin Fuchs <martin-fuchs@gmx.net>
//
/// \file xmlstorage.h
@ -60,7 +60,7 @@
#endif
#if _MSC_VER>=1400
#if _MSC_VER>=1400 // VS2005 or higher
#ifndef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 1
@ -119,26 +119,32 @@ typedef XMLCh XML_Char;
#ifndef _STRING_DEFINED // _STRING_DEFINED only allowed if using xmlstorage.cpp embedded in the project
#if defined(_DEBUG) && defined(_DLL) // DEBUG version only supported with MSVCRTD
#if _MSC_VER==1400
#if _MSC_VER==1500
#pragma comment(lib, "xmlstorage-vc9d")
#elif _MSC_VER==1400
#pragma comment(lib, "xmlstorage-vc8d")
#else
#pragma comment(lib, "xmlstorage-vc6d")
#endif
#else
#ifdef _DLL
#if _MSC_VER==1400
#if _MSC_VER==1500
#pragma comment(lib, "xmlstorage-vc9")
#elif _MSC_VER==1400
#pragma comment(lib, "xmlstorage-vc8")
#else
#pragma comment(lib, "xmlstorage-vc6")
#endif
#elif defined(_MT)
#if _MSC_VER==1400
#if _MSC_VER==1500
#pragma comment(lib, "xmlstorage-vc9t")
#elif _MSC_VER==1400
#pragma comment(lib, "xmlstorage-vc8t")
#else
#pragma comment(lib, "xmlstorage-vc6t")
#endif
#else
// -ML is no more supported by VS2005.
// -ML is no more supported since VS2005.
#pragma comment(lib, "xmlstorage-vc6l")
#endif
#endif
@ -159,9 +165,11 @@ typedef XMLCh XML_Char;
#include <stdio.h> // vsnprintf(), snprintf()
#endif
#else
#else // _WIN32
#include <wchar.h>
#include <stdlib.h>
#include <string.h> // strcasecmp()
#include <stdarg.h>
typedef char CHAR;
@ -199,7 +207,7 @@ typedef const CHAR* LPCTSTR;
#define _tcsnicmp strncasecmp
#endif
#endif
#endif // _WIN32
#ifdef __BORLANDC__
#define _stricmp stricmp
@ -418,6 +426,9 @@ extern const XS_String XS_KEY;
extern const XS_String XS_VALUE;
extern const XS_String XS_PROPERTY;
#define CDATA_START "<![CDATA["
#define CDATA_END "]]>"
#ifndef XS_STRING_UTF8
@ -820,6 +831,7 @@ struct XPathElement
struct XPath : std::list<XPathElement>
{
XPath() : _absolute(false) {}
XPath(const char* path) {init(path);}
XPath(const std::string path) {init(path.c_str());}
@ -1183,7 +1195,7 @@ struct XMLNode : public XS_String
/// set content of a subnode specified by an XPath expression
bool set_sub_content(const XPath& xpath, const XS_String& s, bool cdata=false)
{
XMLNode* node = find_relative(xpath);
XMLNode* node = create_relative(xpath);
if (node) {
node->set_content(s, cdata);
@ -1231,6 +1243,20 @@ struct XMLNode : public XS_String
/// copy matching tree nodes using the given XPath filter expression
bool filter(const XPath& xpath, XMLNode& target) const;
/// XPath find function (const)
const XMLNode* find_relative(const XPath& xpath) const;
/// XPath find function
XMLNode* find_relative(const XPath& xpath);
XMLNode* get_first_child() const
{
if (!_children.empty())
return _children.front();
else
return NULL;
}
protected:
Children _children;
AttributeMap _attributes;
@ -1246,20 +1272,6 @@ protected:
bool _cdata_content;
XMLNode* get_first_child() const
{
if (!_children.empty())
return _children.front();
else
return NULL;
}
/// XPath find function (const)
const XMLNode* find_relative(const XPath& xpath) const;
/// XPath find function
XMLNode* find_relative(const XPath& xpath);
/// relative XPath create function
XMLNode* create_relative(const XPath& xpath);
@ -1590,6 +1602,19 @@ struct XMLPos
return false;
}
/// iterate to the next matching child
bool iterate(const XS_String& child_name, size_t& cnt)
{
XMLNode* node = XPathElement(child_name, cnt).find(_cur);
if (node) {
go_to(node);
++cnt;
return true;
} else
return false;
}
/// move to the position defined by xpath in XML tree
bool go(const XPath& xpath);
@ -1733,6 +1758,8 @@ struct XMLPos
{set_property(key, XS_String(value), name);}
protected:
friend struct const_XMLPos; // access to _root
XMLNode* _root;
XMLNode* _cur;
std::stack<XMLNode*> _stack;
@ -1759,6 +1786,12 @@ struct const_XMLPos
: _root(other._root),
_cur(other._cur)
{ // don't copy _stack
}
const_XMLPos(const XMLPos& other)
: _root(other._root),
_cur(other._cur)
{ // don't copy _stack
}
/// access to current node
@ -1818,6 +1851,19 @@ struct const_XMLPos
return false;
}
/// iterate to the next matching child
bool iterate(const XS_String& child_name, size_t& cnt)
{
const XMLNode* node = XPathElement(child_name, cnt).const_find(_cur);
if (node) {
go_to(node);
++cnt;
return true;
} else
return false;
}
/// move to the position defined by xpath in XML tree
bool go(const XPath& xpath);
@ -2666,6 +2712,11 @@ struct XMLDoc : public XMLNode
return read(reader, system_id);
}
bool read_buffer(const std::string& in, const std::string& system_id=std::string())
{
return read_buffer(in.c_str(), in.length(), system_id);
}
#else // XS_USE_XERCES
bool read_file(LPCTSTR path)
@ -2682,12 +2733,17 @@ struct XMLDoc : public XMLNode
bool read_buffer(const char* buffer, size_t len, const std::string& system_id=std::string())
{
std::istringstream in(std::string(buffer, len));
return read(in, system_id);
return read_buffer(std::string(buffer, len), system_id);
}
bool read(std::istream& in, const std::string& system_id=std::string())
bool read_buffer(const std::string& buffer, const std::string& system_id=std::string())
{
std::istringstream istr(buffer);
return read_stream(istr, system_id);
}
bool read_stream(std::istream& in, const std::string& system_id=std::string())
{
XMLReader reader(this, in);
@ -2880,7 +2936,7 @@ struct XMLWriter
protected:
tofstream* _pofstream;
std::ostream& _out;
const XMLFormat&_format;
XMLFormat _format;
typedef XMLNode::AttributeMap AttrMap;

View file

@ -2,7 +2,7 @@
//
// XML storage C++ classes version 1.3
//
// Copyright (c) 2006, 2007, 2008 Martin Fuchs <martin-fuchs@gmx.net>
// Copyright (c) 2006, 2007, 2008, 2009 Martin Fuchs <martin-fuchs@gmx.net>
//
/// \file xs-native.cpp
@ -37,12 +37,13 @@
*/
#include <precomp.h>
#ifndef XS_NO_COMMENT
#define XS_NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files to enable static linking
#endif
//#include "xmlstorage.h"
#include <precomp.h>
#if !defined(XS_USE_EXPAT) && !defined(XS_USE_XERCES)
@ -131,7 +132,7 @@ struct Buffer
//if (_wptr-_buffer < 3)
// return false;
return !strncmp(_wptr-3, "]]>", 3);
return !strncmp(_wptr-3, CDATA_END, 3);
}
XS_String get_tag() const
@ -318,7 +319,7 @@ bool XMLReaderBase::parse()
_format._doctype.parse(str+10);
c = eat_endl();
} else if (!strncmp(str+2, "[CDATA[", 7)) {
} else if (!strncmp(str+2, "[CDATA[", 7)) { // see CDATA_START
// parse <![CDATA[ ... ]]> strings
while(!buffer.has_CDEnd()) {
c = get();