ReactOS 0.4.15-dev-7961-gdcf9eb0
XMLStorage Namespace Reference

Classes

struct  Buffer
 line buffer for XS-native parser More...
 
struct  const_XMLChildrenFilter
 read only iterator access to children nodes with name filtering More...
 
struct  const_XMLPos
 iterator for XML trees More...
 
struct  DocType
 XML document type description. More...
 
struct  StyleSheet
 XML Stylesheet entry. More...
 
struct  StyleSheetList
 list of StyleSheet entries More...
 
struct  tifstream
 
struct  tofstream
 
struct  XMLBool
 type converter for boolean data More...
 
struct  XMLBoolRef
 type converter for boolean data with write access More...
 
struct  XMLChildrenFilter
 iterator access to children nodes with name filtering More...
 
struct  XMLDoc
 XML document holder. More...
 
struct  XMLDouble
 type converter for numeric data More...
 
struct  XMLDoubleRef
 type converter for numeric data with write access More...
 
struct  XMLError
 XML Error with message and location. More...
 
struct  XMLErrorList
 list of XMLError entries More...
 
struct  XMLFormat
 Management of XML file headers and formating. More...
 
struct  XMLInt
 type converter for integer data More...
 
struct  XMLIntRef
 type converter for integer data with write access More...
 
struct  XMLMessage
 XML message wrapper. More...
 
struct  XMLMessageFromString
 helper structure to read XML messages from strings More...
 
struct  XMLMessageReader
 Reader for XML Messages. More...
 
struct  XMLNode
 in memory representation of an XML node More...
 
struct  XMLPos
 iterator for XML trees More...
 
struct  XMLProperty
 a key/value pair for property data access More...
 
struct  XMLPropertyReader
 utility class to read property settings from a XML tree More...
 
struct  XMLReader
 XML file reader. More...
 
struct  XMLReaderBase
 XML reader base class. More...
 
struct  XMLString
 type converter for string data More...
 
struct  XMLStringRef
 type converter for string data with write access More...
 
struct  XMLWriter
 on the fly XML writer More...
 
struct  XPath
 
struct  XPathElement
 
struct  XS_String
 string class for TCHAR strings More...
 

Typedefs

typedef std::ostringstream fast_ostringstream
 

Enumerations

enum  PRETTY_FLAGS { PRETTY_PLAIN = 0 , PRETTY_LINEFEED = 1 , PRETTY_INDENT = 2 }
 
enum  WRITE_MODE { FORMAT_PLAIN , FORMAT_SMART , FORMAT_ORIGINAL , FORMAT_PRETTY }
 

Functions

static std::string unescape (const char *s, char b, char e)
 remove escape characters from zero terminated string
 
std::string unescape (const char *s)
 
static std::string unescape (const char *s, size_t l, char b, char e)
 remove escape characters from string with specified length
 
std::string unescape (const char *s, size_t l)
 
std::string EncodeXMLString (const XS_String &str, bool cdata)
 encode XML string literals
 
XS_String DecodeXMLString (const std::string &str)
 decode XML string literals
 
std::ostream & operator<< (std::ostream &out, const XMLError &err)
 
const charget_xmlsym_end_utf8 (const char *p)
 
template<typename T >
void read_option (T &var, const_XMLPos &cfg, LPCXSSTR key)
 
template<>
void read_option (int &var, const_XMLPos &cfg, LPCXSSTR key)
 

Variables

const XS_String XS_KEY = XS_KEY_STR
 
const XS_String XS_VALUE = XS_VALUE_STR
 
const XS_String XS_PROPERTY = XS_PROPERTY_STR
 

Typedef Documentation

◆ fast_ostringstream

typedef std::ostringstream XMLStorage::fast_ostringstream

Definition at line 2696 of file xmlstorage.h.

Enumeration Type Documentation

◆ PRETTY_FLAGS

Enumerator
PRETTY_PLAIN 
PRETTY_LINEFEED 
PRETTY_INDENT 

Definition at line 717 of file xmlstorage.h.

717 {
718 PRETTY_PLAIN = 0,
719 PRETTY_LINEFEED = 1,
720 PRETTY_INDENT = 2
721};
@ PRETTY_LINEFEED
Definition: xmlstorage.h:719

◆ WRITE_MODE

Enumerator
FORMAT_PLAIN 
FORMAT_SMART 

write XML without any white space

FORMAT_ORIGINAL 

preserve original white space and comments if present; pretty print otherwise

FORMAT_PRETTY 

write XML stream preserving original white space and comments

pretty print node to stream without preserving original white space

Definition at line 804 of file xmlstorage.h.

804 {
809};
@ FORMAT_SMART
write XML without any white space
Definition: xmlstorage.h:806
@ FORMAT_ORIGINAL
preserve original white space and comments if present; pretty print otherwise
Definition: xmlstorage.h:807
@ FORMAT_PRETTY
write XML stream preserving original white space and comments
Definition: xmlstorage.h:808

Function Documentation

◆ DecodeXMLString()

XS_String XMLStorage::DecodeXMLString ( const std::string &  str)

decode XML string literals

Definition at line 478 of file xmlstorage.cpp.

479{
480#ifdef XS_STRING_UTF8
481 const XS_String& str_utf8 = str;
482#else
483 XS_String str_utf8;
484 assign_utf8(str_utf8, str.c_str(), str.length());
485#endif
486
487 LPCXSSTR s = str_utf8.c_str();
489 LPXSSTR o = buffer;
490
491 for(LPCXSSTR p=s; *p; ++p)
492 if (*p == '&') {
493 if (!XS_nicmp(p+1, XS_TEXT("lt;"), 3)) {
494 *o++ = '<';
495 p += 3;
496 } else if (!XS_nicmp(p+1, XS_TEXT("gt;"), 3)) {
497 *o++ = '>';
498 p += 3;
499 } else if (!XS_nicmp(p+1, XS_TEXT("amp;"), 4)) {
500 *o++ = '&';
501 p += 4;
502 } else if (!XS_nicmp(p+1, XS_TEXT("quot;"), 5)) {
503 *o++ = '"';
504 p += 5;
505 } else if (!XS_nicmp(p+1, XS_TEXT("apos;"), 5)) {
506 *o++ = '\'';
507 p += 5;
508 } else //@@ maybe decode "&#xx;" special characters
509 *o++ = *p;
510 } else if (*p=='<' && !XS_nicmp(p+1,XS_TEXT("![CDATA["),8)) {
512 if (e) {
513 p += 9;
514 size_t l = e - p;
515 memcpy(o, p, l);
516 o += l;
517 p = e + 2;
518 } else
519 *o++ = *p;
520 } else
521 *o++ = *p;
522
523 return XS_String(buffer, o-buffer);
524}
r l[0]
Definition: byte_order.h:168
GLdouble s
Definition: gl.h:2039
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat p
Definition: glext.h:8902
#define e
Definition: ke_i.h:82
#define alloca
Definition: malloc.h:357
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
const WCHAR * str
string class for TCHAR strings
Definition: xmlstorage.h:293
#define XS_nicmp
Definition: xmlstorage.h:243
#define XS_CHAR
Definition: xmlstorage.h:236
#define LPCXSSTR
Definition: xmlstorage.h:239
#define XS_TEXT(x)
Definition: xmlstorage.h:237
#define XS_len
Definition: xmlstorage.h:246
#define LPXSSTR
Definition: xmlstorage.h:238
#define XS_strstr
Definition: xmlstorage.h:249
#define CDATA_END
Definition: xmlstorage.h:436

Referenced by XMLStorage::Buffer::get_attributes(), and XMLStorage::XMLNode::get_content().

◆ EncodeXMLString()

std::string XMLStorage::EncodeXMLString ( const XS_String str,
bool  cdata 
)

encode XML string literals

Definition at line 374 of file xmlstorage.cpp.

375{
376 LPCXSSTR s = str.c_str();
377 size_t l = XS_len(s);
378
379 if (cdata) {
380 // encode the whole string in a CDATA section
381 std::string ret = CDATA_START;
382
383#ifdef XS_STRING_UTF8
384 ret += str;
385#else
386 ret += get_utf8(str);
387#endif
388
389 ret += CDATA_END;
390
391 return ret;
392 } else if (l <= BUFFER_LEN) {
393 LPXSSTR buffer = (LPXSSTR)alloca(6*sizeof(XS_CHAR)*XS_len(s)); // worst case "&quot;" / "&apos;"
394 LPXSSTR o = buffer;
395
396 for(LPCXSSTR p=s; *p; ++p)
397 switch(*p) {
398 case '&':
399 *o++ = '&'; *o++ = 'a'; *o++ = 'm'; *o++ = 'p'; *o++ = ';'; // "&amp;"
400 break;
401
402 case '<':
403 *o++ = '&'; *o++ = 'l'; *o++ = 't'; *o++ = ';'; // "&lt;"
404 break;
405
406 case '>':
407 *o++ = '&'; *o++ = 'g'; *o++ = 't'; *o++ = ';'; // "&gt;"
408 break;
409
410 case '"':
411 *o++ = '&'; *o++ = 'q'; *o++ = 'u'; *o++ = 'o'; *o++ = 't'; *o++ = ';'; // "&quot;"
412 break;
413
414 case '\'':
415 *o++ = '&'; *o++ = 'a'; *o++ = 'p'; *o++ = 'o'; *o++ = 's'; *o++ = ';'; // "&apos;"
416 break;
417
418 default:
419 if ((unsigned)*p<0x20 && *p!='\t' && *p!='\r' && *p!='\n') {
420 char b[16];
421 sprintf(b, "&#%d;", (unsigned)*p);
422 for(const char*q=b; *q; )
423 *o++ = *q++;
424 } else
425 *o++ = *p;
426 }
427
428#ifdef XS_STRING_UTF8
429 return XS_String(buffer, o-buffer);
430#else
431 return get_utf8(buffer, o-buffer);
432#endif
433 } else { // l > BUFFER_LEN
434 // alternative code for larger strings using ostringstream
435 // and avoiding to use alloca() for preallocated memory
437
438 LPCXSSTR s = str.c_str();
439
440 for(LPCXSSTR p=s; *p; ++p)
441 switch(*p) {
442 case '&':
443 out << "&amp;";
444 break;
445
446 case '<':
447 out << "&lt;";
448 break;
449
450 case '>':
451 out << "&gt;";
452 break;
453
454 case '"':
455 out << "&quot;";
456 break;
457
458 case '\'':
459 out << "&apos;";
460 break;
461
462 default:
463 if ((unsigned)*p<0x20 && *p!='\t' && *p!='\r' && *p!='\n')
464 out << "&#" << (unsigned)*p << ";";
465 else
466 out << *p;
467 }
468
469#ifdef XS_STRING_UTF8
470 return XS_String(out.str());
471#else
472 return get_utf8(out.str());
473#endif
474 }
475}
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define BUFFER_LEN
Definition: utility.h:97
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static unsigned(__cdecl *hash_bstr)(bstr_t s)
std::ostringstream fast_ostringstream
Definition: xmlstorage.h:2696
static FILE * out
Definition: regtests2xml.c:44
int ret
#define CDATA_START
Definition: xmlstorage.h:435

Referenced by XMLStorage::XMLNode::original_write_worker(), XMLStorage::XMLNode::plain_write_worker(), XMLStorage::XMLNode::pretty_write_worker(), XMLStorage::XMLNode::set_content(), XMLStorage::XMLWriter::set_content(), XMLStorage::XMLNode::smart_write_worker(), XMLStorage::XMLWriter::write_attributes(), XMLStorage::XMLWriter::write_post(), and XMLStorage::XMLWriter::write_pre().

◆ get_xmlsym_end_utf8()

const char * XMLStorage::get_xmlsym_end_utf8 ( const char p)

Definition at line 682 of file xmlstorage.cpp.

683{
684 for(; *p; ++p) {
685 char c = *p;
686
687 // NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
688 if (c == '\xC3') // UTF-8 escape character
689 ++p; //TODO only continue on umlaut characters
690 else if (!isalnum(c) && c!='.' && c!='-' && c!='_' && c!=':')
691 break;
692 }
693
694 return p;
695}
const GLubyte * c
Definition: glext.h:8905
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)

Referenced by XMLStorage::Buffer::get_attributes(), XMLStorage::Buffer::get_tag(), and XMLStorage::DocType::parse().

◆ operator<<()

std::ostream & XMLStorage::operator<< ( std::ostream &  out,
const XMLError err 
)

Definition at line 673 of file xmlstorage.cpp.

674{
675 out << err._systemId << "(" << err._line << ") [column " << err._column << "] : "
676 << err._message;
677
678 return out;
679}
#define err(...)

◆ read_option() [1/2]

template<>
void XMLStorage::read_option ( int var,
const_XMLPos cfg,
LPCXSSTR  key 
)
inline

Definition at line 2265 of file xmlstorage.h.

2266 {
2267 const XS_String& val = cfg.get(key);
2268
2269 if (!val.empty())
2270 var = XS_toi(val.c_str());
2271 }
GLuint GLfloat * val
Definition: glext.h:7180
const char * var
Definition: shader.c:5666
XS_String get(const XS_String &attr_name) const
attribute access
Definition: xmlstorage.h:1829
Definition: copy.c:22
#define XS_toi
Definition: xmlstorage.h:244

◆ read_option() [2/2]

template<typename T >
void XMLStorage::read_option ( T var,
const_XMLPos cfg,
LPCXSSTR  key 
)
inline

Definition at line 2255 of file xmlstorage.h.

2256 {
2257 const XS_String& val = cfg.get(key);
2258
2259 if (!val.empty())
2260 var = val;
2261 }

◆ unescape() [1/4]

std::string XMLStorage::unescape ( const char s)
inline

Definition at line 84 of file xmlstorage.cpp.

85{
86 return unescape(s, '"', '"');
87}
BOOL unescape(WCHAR *str, size_t *len)
Definition: lex.c:227

◆ unescape() [2/4]

static std::string XMLStorage::unescape ( const char s,
char  b,
char  e 
)
static

remove escape characters from zero terminated string

Definition at line 67 of file xmlstorage.cpp.

68{
69 const char* end = s + strlen(s);
70
71// if (*s == b)
72// ++s;
73//
74// if (end>s && end[-1]==e)
75// --end;
76
77 if (*s == b)
78 if (end>s && end[-1]==e)
79 ++s, --end;
80
81 return std::string(s, end-s);
82}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint GLuint end
Definition: gl.h:1545

Referenced by XMLStorage::XPathElement::parse(), and unescape().

◆ unescape() [3/4]

std::string XMLStorage::unescape ( const char s,
size_t  l 
)
inline

Definition at line 107 of file xmlstorage.cpp.

108{
109 return unescape(s, l, '"', '"');
110}

◆ unescape() [4/4]

static std::string XMLStorage::unescape ( const char s,
size_t  l,
char  b,
char  e 
)
static

remove escape characters from string with specified length

Definition at line 90 of file xmlstorage.cpp.

91{
92 const char* end = s + l;
93
94// if (*s == b)
95// ++s;
96//
97// if (end>s && end[-1]==e)
98// --end;
99
100 if (*s == b)
101 if (end>s && end[-1]==e)
102 ++s, --end;
103
104 return std::string(s, end-s);
105}

Variable Documentation

◆ XS_KEY

const XS_String XMLStorage::XS_KEY = XS_KEY_STR

Definition at line 61 of file xmlstorage.cpp.

Referenced by XMLStorage::XMLPos::set_property().

◆ XS_PROPERTY

const XS_String XMLStorage::XS_PROPERTY = XS_PROPERTY_STR

Definition at line 63 of file xmlstorage.cpp.

◆ XS_VALUE

const XS_String XMLStorage::XS_VALUE = XS_VALUE_STR

Definition at line 62 of file xmlstorage.cpp.

Referenced by XMLStorage::XMLPos::set_property().