ReactOS  r76032
XMLStorage Namespace Reference

Classes

struct  XS_String
 string class for TCHAR strings More...
 
struct  tifstream
 
struct  tofstream
 
struct  XMLError
 XML Error with message and location. More...
 
struct  XMLErrorList
 list of XMLError entries More...
 
struct  StyleSheet
 XML Stylesheet entry. More...
 
struct  StyleSheetList
 list of StyleSheet entries More...
 
struct  DocType
 XML document type description. More...
 
struct  XMLFormat
 Management of XML file headers and formating. More...
 
struct  XPathElement
 
struct  XPath
 
struct  XMLNode
 in memory representation of an XML node More...
 
struct  XMLChildrenFilter
 iterator access to children nodes with name filtering More...
 
struct  const_XMLChildrenFilter
 read only iterator access to children nodes with name filtering More...
 
struct  XMLPos
 iterator for XML trees More...
 
struct  const_XMLPos
 iterator for XML trees More...
 
struct  XMLBool
 type converter for boolean data More...
 
struct  XMLBoolRef
 type converter for boolean data with write access More...
 
struct  XMLInt
 type converter for integer data More...
 
struct  XMLIntRef
 type converter for integer data with write access More...
 
struct  XMLDouble
 type converter for numeric data More...
 
struct  XMLDoubleRef
 type converter for numeric data with write access More...
 
struct  XMLString
 type converter for string data More...
 
struct  XMLStringRef
 type converter for string data with write access 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  XMLReaderBase
 XML reader base class. More...
 
struct  XMLReader
 XML file reader. More...
 
struct  XMLDoc
 XML document holder. 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  XMLWriter
 on the fly XML writer More...
 
struct  Buffer
 line buffer for XS-native parser 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 More...
 
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 More...
 
std::string unescape (const char *s, size_t l)
 
std::string EncodeXMLString (const XS_String &str, bool cdata)
 encode XML string literals More...
 
XS_String DecodeXMLString (const std::string &str)
 decode XML string literals More...
 
std::ostreamoperator<< (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

Enumeration Type Documentation

Enumerator
PRETTY_PLAIN 
PRETTY_LINEFEED 
PRETTY_INDENT 

Definition at line 717 of file xmlstorage.h.

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  {
805  FORMAT_PLAIN,
806  FORMAT_SMART,
809 };
write XML stream preserving original white space and comments
Definition: xmlstorage.h:808
preserve original white space and comments if present; pretty print otherwise
Definition: xmlstorage.h:807
write XML without any white space
Definition: xmlstorage.h:806

Function Documentation

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

decode XML string literals

Definition at line 478 of file xmlstorage.cpp.

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

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();
488  LPXSSTR buffer = (LPXSSTR)alloca(sizeof(XS_CHAR)*XS_len(s));
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 }
#define XS_nicmp
Definition: xmlstorage.h:243
#define XS_len
Definition: xmlstorage.h:246
#define o(x)
Definition: extensions.c:56
GLuint buffer
Definition: glext.h:5915
#define alloca
Definition: malloc.h:361
#define e
Definition: ke_i.h:82
const WCHAR * str
r l[0]
Definition: byte_order.h:167
#define XS_strstr
Definition: xmlstorage.h:249
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
#define XS_CHAR
Definition: xmlstorage.h:236
#define LPXSSTR
Definition: xmlstorage.h:238
#define XS_TEXT(x)
Definition: xmlstorage.h:237
GLfloat GLfloat p
Definition: glext.h:8902
#define CDATA_END
Definition: xmlstorage.h:436
#define LPCXSSTR
Definition: xmlstorage.h:239
std::string XMLStorage::EncodeXMLString ( const XS_String &  str,
bool  cdata 
)

encode XML string literals

Definition at line 374 of file xmlstorage.cpp.

Referenced by XMLStorage::XMLNode::original_write_worker(), XMLStorage::XMLNode::set_content(), and XMLStorage::XMLWriter::set_content().

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
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 }
#define XS_len
Definition: xmlstorage.h:246
#define o(x)
Definition: extensions.c:56
GLuint buffer
Definition: glext.h:5915
std::ostringstream fast_ostringstream
Definition: xmlstorage.h:2696
#define alloca
Definition: malloc.h:361
#define sprintf(buf, format,...)
Definition: sprintf.c:55
const WCHAR * str
#define BUFFER_LEN
Definition: utility.h:97
#define CDATA_START
Definition: xmlstorage.h:435
r l[0]
Definition: byte_order.h:167
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static FILE * out
Definition: regtests2xml.c:44
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
int ret
GLdouble s
Definition: gl.h:2039
#define XS_CHAR
Definition: xmlstorage.h:236
char string[160]
Definition: util.h:11
#define LPXSSTR
Definition: xmlstorage.h:238
GLfloat GLfloat p
Definition: glext.h:8902
#define CDATA_END
Definition: xmlstorage.h:436
#define LPCXSSTR
Definition: xmlstorage.h:239
const char * XMLStorage::get_xmlsym_end_utf8 ( const char p)

Definition at line 682 of file xmlstorage.cpp.

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

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 }
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
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 }
int int int * err
Definition: fci.h:172
static FILE * out
Definition: regtests2xml.c:44
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  }
GLuint GLfloat * val
Definition: glext.h:7180
Definition: path.c:42
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
#define XS_toi
Definition: xmlstorage.h:244
Definition: path.c:42
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.

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

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
#define e
Definition: ke_i.h:82
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLdouble s
Definition: gl.h:2039
char string[160]
Definition: util.h:11
std::string XMLStorage::unescape ( const char s)
inline

Definition at line 84 of file xmlstorage.cpp.

85 {
86  return unescape(s, '"', '"');
87 }
GLdouble s
Definition: gl.h:2039
std::string unescape(const char *s, size_t l)
Definition: xmlstorage.cpp:107
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 }
GLuint GLuint end
Definition: gl.h:1545
#define e
Definition: ke_i.h:82
r l[0]
Definition: byte_order.h:167
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLdouble s
Definition: gl.h:2039
char string[160]
Definition: util.h:11
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 }
r l[0]
Definition: byte_order.h:167
GLdouble s
Definition: gl.h:2039
std::string unescape(const char *s, size_t l)
Definition: xmlstorage.cpp:107

Variable Documentation

const XS_String XMLStorage::XS_KEY = XS_KEY_STR

Definition at line 61 of file xmlstorage.cpp.

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

const XS_String XMLStorage::XS_PROPERTY = XS_PROPERTY_STR

Definition at line 63 of file xmlstorage.cpp.

const XS_String XMLStorage::XS_VALUE = XS_VALUE_STR

Definition at line 62 of file xmlstorage.cpp.

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