Author: martinf Date: Sun Jan 25 05:20:47 2009 New Revision: 39084
URL: http://svn.reactos.org/svn/reactos?rev=39084&view=rev Log: update XMLStorage to the current version, compatible to VS2008 and GCC@Linux
Modified: trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp trunk/reactos/base/shell/explorer/utility/xmlstorage.h trunk/reactos/base/shell/explorer/utility/xs-native.cpp
Modified: trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/utility... ============================================================================== --- trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp [iso-8859-1] (original) +++ trunk/reactos/base/shell/explorer/utility/xmlstorage.cpp [iso-8859-1] Sun Jan 25 05:20:47 2009 @@ -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* 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 @@
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 @@ ret += get_utf8(str); #endif
- ret += "]]>"; + ret += CDATA_END;
return ret; } else if (l <= BUFFER_LEN) { @@ -504,7 +507,7 @@ } 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 @@ out << '>';
if (_cdata_content) - out << EncodeXMLString(DecodeXMLString(_content), true); + out << CDATA_START << _content << CDATA_END; else out << _content;
@@ -632,7 +635,7 @@ 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 @@ 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);
Modified: trunk/reactos/base/shell/explorer/utility/xmlstorage.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/utility... ============================================================================== --- trunk/reactos/base/shell/explorer/utility/xmlstorage.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/explorer/utility/xmlstorage.h [iso-8859-1] Sun Jan 25 05:20:47 2009 @@ -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 @@
#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 @@ #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 @@ #define _tcsnicmp strncasecmp #endif
-#endif +#endif // _WIN32
#ifdef __BORLANDC__ #define _stricmp stricmp @@ -418,6 +426,9 @@ 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 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 @@ /// 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 @@ /// 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; @@ -1245,20 +1271,6 @@ #endif
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 @@ 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 @@ {set_property(key, XS_String(value), name);}
protected: + friend struct const_XMLPos; // access to _root + XMLNode* _root; XMLNode* _cur; std::stack<XMLNode*> _stack; @@ -1756,6 +1783,12 @@ }
const_XMLPos(const const_XMLPos& other) + : _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 @@ -1813,6 +1846,19 @@
if (node) { go_to(node); + return true; + } else + 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; @@ -2666,6 +2712,11 @@ 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 @@
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); - } - - bool read(std::istream& in, const std::string& system_id=std::string()) + return read_buffer(std::string(buffer, len), system_id); + } + + 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 @@ protected: tofstream* _pofstream; std::ostream& _out; - const XMLFormat&_format; + XMLFormat _format;
typedef XMLNode::AttributeMap AttrMap;
Modified: trunk/reactos/base/shell/explorer/utility/xs-native.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/utility... ============================================================================== --- trunk/reactos/base/shell/explorer/utility/xs-native.cpp [iso-8859-1] (original) +++ trunk/reactos/base/shell/explorer/utility/xs-native.cpp [iso-8859-1] Sun Jan 25 05:20:47 2009 @@ -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 @@ //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 @@ _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();