Classes | Typedefs | Enumerations | Functions | Variables

XMLStorage Namespace Reference

Classes

struct  TmpHeap
struct  XS_String
 string class for TCHAR strings More...
struct  tifstream
struct  tofstream
struct  XMLLocation
 location of XML Node including XML file name More...
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  HeaderlessXMLFormat
struct  XS_SMNode
struct  XS_StringMap
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  XMLReaderBase
 XML reader base class. More...
struct  XMLReader
 XML file reader. More...
struct  ReadBuffer
struct  ParseContext
struct  XMLDoc
 XML document holder. More...
struct  XMLStateReader
struct  XMLStreamReader
struct  XMLStreamChildrenIterator
 read only iterator access to XMLStreamReader nodes More...
struct  XMLStreamChildrenFilter
 read only iterator access to children nodes to XMLStreamReader nodes with name filtering 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  XMLInt64
 type converter for integer data More...
struct  XMLInt64Ref
 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  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...

Typedefs

typedef long long INT64
typedef unsigned long long UINT64
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 XS_String unescape (LPCXSSTR s, TCHAR b, TCHAR e)
 remove escape characters from zero terminated string
XS_String unescape (LPCXSSTR s)
static XS_String unescape (LPCXSSTR s, size_t l, char b, char e)
 remove escape characters from string with specified length
XS_String unescape (LPCXSSTR s, size_t l)
std::string EncodeXMLString (const XS_String &str, bool cdata)
 encode XML string literals
XS_String DecodeXMLString (const std::string &str_utf8)
 decode XML string literals
std::ostream & operator<< (std::ostream &out, const XMLError &err)
const char * get_xmlsym_end_utf8 (const char *p)
int _istspace (TCHAR c)
LPCXSSTR safe_skip_space (LPCXSSTR s)
template<typename T >
XS_String from_utf8 (const T &s)
XS_String from_utf8 (const char *s, size_t l)
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

typedef std::ostringstream XMLStorage::fast_ostringstream

Definition at line 2927 of file xmlstorage.h.

typedef long long XMLStorage::INT64

Definition at line 305 of file xmlstorage.h.

typedef unsigned long long XMLStorage::UINT64

Definition at line 306 of file xmlstorage.h.


Enumeration Type Documentation

Enumerator:
PRETTY_PLAIN 
PRETTY_LINEFEED 
PRETTY_INDENT 

Definition at line 945 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 1065 of file xmlstorage.h.

                {
    FORMAT_PLAIN,       /// write XML without any white space
    FORMAT_SMART,       /// preserve original white space and comments if present; pretty print otherwise
    FORMAT_ORIGINAL,    /// write XML stream preserving original white space and comments
    FORMAT_PRETTY       /// pretty print node to stream without preserving original white space
};

Function Documentation

int XMLStorage::_istspace ( TCHAR  c ) [inline]

Definition at line 548 of file xmlstorage.h.

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

{
#ifdef UNICODE
    return u_isspace(c);
#else
    return isspace(c);
#endif
}

Here is the caller graph for this function:

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

decode XML string literals

Definition at line 516 of file xmlstorage.cpp.

References CDATA_END, LPCXSSTR, LPXSSTR, TMP_ALLOC, XS_CHAR, XS_len, XS_nicmp, XS_strstr, and XS_TEXT.

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

{
#ifdef XS_STRING_UTF8
    const XS_String& str = str_utf8;
#else
    XS_String str;
    assign_utf8(str, str_utf8.c_str(), str_utf8.length());
#endif

    LPCXSSTR s = str.c_str();
    size_t l = XS_len(s);

    TMP_ALLOC(XS_CHAR, buffer, heap, l);

    LPXSSTR o = buffer;
    for(LPCXSSTR p=s; *p; ++p)
        if (*p == '&') {
            if (!XS_nicmp(p+1, XS_TEXT("lt;"), 3)) {
                *o++ = '<';
                p += 3;
            } else if (!XS_nicmp(p+1, XS_TEXT("gt;"), 3)) {
                *o++ = '>';
                p += 3;
            } else if (!XS_nicmp(p+1, XS_TEXT("amp;"), 4)) {
                *o++ = '&';
                p += 4;
            } else if (!XS_nicmp(p+1, XS_TEXT("quot;"), 5)) {
                *o++ = '"';
                p += 5;
            } else if (!XS_nicmp(p+1, XS_TEXT("apos;"), 5)) {
                *o++ = '\'';
                p += 5;
            } 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(CDATA_END));
            if (e) {
                p += 9;
                size_t l = e - p;
                memcpy(o, p, l);
                o += l;
                p = e + 2;
            } else
                *o++ = *p;
        } else
            *o++ = *p;

    return XS_String(buffer, o-buffer);
}

Here is the caller graph for this function:

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

encode XML string literals

Definition at line 391 of file xmlstorage.cpp.

References BUFFER_LEN, CDATA_END, CDATA_START, LPCXSSTR, LPXSSTR, XS_CHAR, and XS_len.

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

{
    LPCXSSTR s = str.c_str();
    size_t l = XS_len(s);

    if (cdata) {
         // encode the whole string in a CDATA section
        std::string ret = CDATA_START;

#ifdef XS_STRING_UTF8
        ret += str;
#else
        ret += get_utf8(str);
#endif

#ifdef XS_STRICT_XML_1_0
        for(char*p=&ret.at(9); *p; ++p) // strlen(CDATA_START) == 9
            if ((unsigned)*p<0x20 && *p!='\t' && *p!='\r' && *p!='\n')
                *p = '?';
#endif

        ret += CDATA_END;

        return ret;
    } else if (l <= BUFFER_LEN) {
        LPXSSTR buffer = (LPXSSTR)alloca(6*sizeof(XS_CHAR)*XS_len(s));  // worst case "&quot;" / "&apos;"
        LPXSSTR o = buffer;

        for(LPCXSSTR p=s; *p; ++p)
            switch(*p) {
              case '&':
                *o++ = '&'; *o++ = 'a'; *o++ = 'm'; *o++ = 'p'; *o++ = ';';             // "&amp;"
                break;

              case '<':
                *o++ = '&'; *o++ = 'l'; *o++ = 't'; *o++ = ';';                         // "&lt;"
                break;

              case '>':
                *o++ = '&'; *o++ = 'g'; *o++ = 't'; *o++ = ';';                         // "&gt;"
                break;

              case '"':
                *o++ = '&'; *o++ = 'q'; *o++ = 'u'; *o++ = 'o'; *o++ = 't'; *o++ = ';'; // "&quot;"
                break;

              case '\'':
                *o++ = '&'; *o++ = 'a'; *o++ = 'p'; *o++ = 'o'; *o++ = 's'; *o++ = ';'; // "&apos;"
                break;

              default:
                if ((unsigned)*p>=0x20 || *p=='\t' || *p=='\r' || *p=='\n')
                    *o++ = *p;
                else {
#ifdef XS_STRICT_XML_1_0
                    *o++ = '?';
#else
                    char b[16];
                    sprintf(b, "&#%d;", (unsigned)*p);
                    for(const char*q=b; *q; )
                        *o++ = *q++;
#endif
                }
            }

#ifdef XS_STRING_UTF8
        return XS_String(buffer, o-buffer);
#else
        return get_utf8(buffer, o-buffer);
#endif
    } else { // l > BUFFER_LEN
         // alternative code for larger strings using ostringstream
         // and avoiding to use alloca() for preallocated memory
        fast_ostringstream out;

#ifdef XS_STRING_UTF8
        LPCXSSTR s = str.c_str();
#else
        std::string utf8_str = get_utf8(str);
        const char* s = utf8_str.c_str();
#endif

        for(const char* p=s; *p; ++p)
            switch(*p) {
              case '&':
                out << "&amp;";
                break;

              case '<':
                out << "&lt;";
                break;

              case '>':
                out << "&gt;";
                break;

              case '"':
                out << "&quot;";
                break;

              case '\'':
                out << "&apos;";
                break;

              default:
                if ((unsigned)*p>=0x20 || *p=='\t' || *p=='\r' || *p=='\n')
                    out << (unsigned char)*p;
                else {
#ifdef XS_STRICT_XML_1_0
                    out << '?';
#else
                    out << "&#" << (unsigned)*p << ";";
#endif
                }
            }

#ifdef XS_STRING_UTF8
        return XS_String(out.str());
#else
        return out.str();
#endif
    }
}

Here is the caller graph for this function:

template<typename T >
XS_String XMLStorage::from_utf8 ( const T &  s ) [inline]

Definition at line 573 of file xmlstorage.h.

Referenced by XMLStorage::ReadBuffer::get_tag().

{
    return s;
}

Here is the caller graph for this function:

XS_String XMLStorage::from_utf8 ( const char *  s,
size_t  l 
) [inline]

Definition at line 578 of file xmlstorage.h.

{
    return XS_String(s, l);
}
const char * XMLStorage::get_xmlsym_end_utf8 ( const char *  p )

Definition at line 748 of file xmlstorage.cpp.

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

{
    for(; *p; ++p) {
        char c = *p;

        // NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
        if (c == '\xC3')    // UTF-8 escape character
            ++p;    //TODO only continue on umlaut characters
        else if (!isalnum(c) && c!='.' && c!='-' && c!='_' && c!=':')
            break;
    }

    return p;
}

Here is the caller graph for this function:

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

Definition at line 713 of file xmlstorage.cpp.

{
    out << err._systemId << "(" << err._line << ")";

    if (err._column > 1)
        out << " [column " << err._column << "]";

    out << " : " << err._message;

    return out;
}
template<>
void XMLStorage::read_option ( int &  var,
const_XMLPos &  cfg,
LPCXSSTR  key 
) [inline]

Definition at line 3951 of file xmlstorage.h.

References XMLStorage::const_XMLPos::get(), and XS_toi.

    {
        const XS_String& val = cfg.get(key);

        if (!val.empty())
            var = XS_toi(val.c_str());
    }

Here is the call graph for this function:

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

Definition at line 3941 of file xmlstorage.h.

References XMLStorage::const_XMLPos::get().

    {
        const XS_String& val = cfg.get(key);

        if (!val.empty())
            var = val;
    }

Here is the call graph for this function:

LPCXSSTR XMLStorage::safe_skip_space ( LPCXSSTR  s ) [inline]

Definition at line 558 of file xmlstorage.h.

References _istspace(), and XS_EMPTY_STR.

Referenced by XMLStorage::XMLBool::XMLBool(), XMLStorage::XMLDouble::XMLDouble(), XMLStorage::XMLInt::XMLInt(), and XMLStorage::XMLInt64::XMLInt64().

{
    if (s) {
         // strip leading white space
        while(_istspace(*s))
            ++s;

        return s;
    } else
        return XS_EMPTY_STR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

XS_String XMLStorage::unescape ( LPCXSSTR  s ) [inline]

Definition at line 79 of file xmlstorage.cpp.

References TEXT, and unescape().

{
    if (*s == TEXT('\''))
        return unescape(s, TEXT('\''), TEXT('\''));
    else
        return unescape(s, TEXT('"'), TEXT('"'));
}

Here is the call graph for this function:

static XS_String XMLStorage::unescape ( LPCXSSTR  s,
size_t  l,
char  b,
char  e 
) [static]

remove escape characters from string with specified length

Definition at line 88 of file xmlstorage.cpp.

References LPCXSSTR.

{
    LPCXSSTR end = s + l;

    if (*s == b)
        if (end>s+1 && end[-1]==e)
            ++s, --end;

    return XS_String(s, end-s);
}
static XS_String XMLStorage::unescape ( LPCXSSTR  s,
TCHAR  b,
TCHAR  e 
) [static]

remove escape characters from zero terminated string

Definition at line 66 of file xmlstorage.cpp.

References _tcslen, and LPCXSSTR.

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

{
    if (*s == b) {
        LPCXSSTR end = s + _tcslen(s);

        if (end>s && end[-1]==e)
            ++s, --end;

        return XS_String(s, end-s);
    } else
        return s;
}

Here is the caller graph for this function:

XS_String XMLStorage::unescape ( LPCXSSTR  s,
size_t  l 
) [inline]

Definition at line 99 of file xmlstorage.cpp.

References TEXT, and unescape().

{
    if (*s == '\'')
        return unescape(s, l, TEXT('\''), TEXT('\''));
    else if (*s == '"')
        return unescape(s, l, TEXT('"'), TEXT('"'));
    else
        return XS_String(s, l);
}

Here is the call graph for this function:


Variable Documentation

const XS_String XMLStorage::XS_KEY = XS_KEY_STR

Definition at line 60 of file xmlstorage.cpp.

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

const XS_String XMLStorage::XS_PROPERTY = XS_PROPERTY_STR

Definition at line 62 of file xmlstorage.cpp.

const XS_String XMLStorage::XS_VALUE = XS_VALUE_STR

Definition at line 61 of file xmlstorage.cpp.

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