osgEarth 2.1.1
|
#include <tinyxml.h>
Classes | |
struct | Entity |
Public Types | |
enum | { TIXML_NO_ERROR = 0, TIXML_ERROR, TIXML_ERROR_OPENING_FILE, TIXML_ERROR_PARSING_ELEMENT, TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, TIXML_ERROR_READING_ELEMENT_VALUE, TIXML_ERROR_READING_ATTRIBUTES, TIXML_ERROR_PARSING_EMPTY, TIXML_ERROR_READING_END_TAG, TIXML_ERROR_PARSING_UNKNOWN, TIXML_ERROR_PARSING_COMMENT, TIXML_ERROR_PARSING_DECLARATION, TIXML_ERROR_DOCUMENT_EMPTY, TIXML_ERROR_EMBEDDED_NULL, TIXML_ERROR_PARSING_CDATA, TIXML_ERROR_DOCUMENT_TOP_ONLY, TIXML_ERROR_STRING_COUNT } |
Public Member Functions | |
TiXmlBase () | |
virtual | ~TiXmlBase () |
virtual void | Print (FILE *cfile, int depth) const =0 |
int | Row () const |
int | Column () const |
See Row() | |
void | SetUserData (void *user) |
Set a pointer to arbitrary user data. | |
void * | GetUserData () |
Get a pointer to arbitrary user data. | |
const void * | GetUserData () const |
Get a pointer to arbitrary user data. | |
virtual const char * | Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0 |
Static Public Member Functions | |
static void | SetCondenseWhiteSpace (bool condense) |
static bool | IsWhiteSpaceCondensed () |
Return the current white space setting. | |
static void | EncodeString (const TIXML_STRING &str, TIXML_STRING *out) |
Static Public Attributes | |
static const int | utf8ByteTable [256] |
Static Protected Member Functions | |
static const char * | SkipWhiteSpace (const char *, TiXmlEncoding encoding) |
static bool | IsWhiteSpace (char c) |
static bool | IsWhiteSpace (int c) |
static const char * | ReadName (const char *p, TIXML_STRING *name, TiXmlEncoding encoding) |
static const char * | ReadText (const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding) |
static const char * | GetEntity (const char *in, char *value, int *length, TiXmlEncoding encoding) |
static const char * | GetChar (const char *p, char *_value, int *length, TiXmlEncoding encoding) |
static bool | StringEqual (const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding) |
static int | IsAlpha (unsigned char anyByte, TiXmlEncoding encoding) |
static int | IsAlphaNum (unsigned char anyByte, TiXmlEncoding encoding) |
static int | ToLower (int v, TiXmlEncoding encoding) |
static void | ConvertUTF32ToUTF8 (unsigned long input, char *output, int *length) |
Protected Attributes | |
TiXmlCursor | location |
void * | userData |
Field containing a generic user pointer. | |
Static Protected Attributes | |
static const char * | errorString [TIXML_ERROR_STRING_COUNT] |
Private Types | |
enum | { NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6 } |
Private Member Functions | |
TiXmlBase (const TiXmlBase &) | |
void | operator= (const TiXmlBase &base) |
Static Private Attributes | |
static Entity | entity [NUM_ENTITY] |
static bool | condenseWhiteSpace = true |
Friends | |
class | TiXmlNode |
class | TiXmlElement |
class | TiXmlDocument |
TiXmlBase is a base class for every class in TinyXml. It does little except to establish that TinyXml classes can be printed and provide some utility functions.
In XML, the document and elements can contain other elements and other types of nodes.
A Document can contain: Element (container or leaf) Comment (leaf) Unknown (leaf) Declaration( leaf ) An Element can contain: Element (container or leaf) Text (leaf) Attributes (not on tree) Comment (leaf) Unknown (leaf) A Decleration contains: Attributes (not on tree)
anonymous enum |
Definition at line 264 of file tinyxml.h.
{ TIXML_NO_ERROR = 0, TIXML_ERROR, TIXML_ERROR_OPENING_FILE, TIXML_ERROR_PARSING_ELEMENT, TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, TIXML_ERROR_READING_ELEMENT_VALUE, TIXML_ERROR_READING_ATTRIBUTES, TIXML_ERROR_PARSING_EMPTY, TIXML_ERROR_READING_END_TAG, TIXML_ERROR_PARSING_UNKNOWN, TIXML_ERROR_PARSING_COMMENT, TIXML_ERROR_PARSING_DECLARATION, TIXML_ERROR_DOCUMENT_EMPTY, TIXML_ERROR_EMBEDDED_NULL, TIXML_ERROR_PARSING_CDATA, TIXML_ERROR_DOCUMENT_TOP_ONLY, TIXML_ERROR_STRING_COUNT };
anonymous enum [private] |
Definition at line 406 of file tinyxml.h.
{ NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6 };
TiXmlBase::TiXmlBase | ( | const TiXmlBase & | ) | [private] |
void TiXmlBase::ConvertUTF32ToUTF8 | ( | unsigned long | input, |
char * | output, | ||
int * | length | ||
) | [static, protected] |
Definition at line 88 of file tinyxmlparser.cpp.
{ const unsigned long BYTE_MASK = 0xBF; const unsigned long BYTE_MARK = 0x80; const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; if (input < 0x80) *length = 1; else if ( input < 0x800 ) *length = 2; else if ( input < 0x10000 ) *length = 3; else if ( input < 0x200000 ) *length = 4; else { *length = 0; return; } // This code won't covert this correctly anyway. output += *length; // Scary scary fall throughs. switch (*length) { case 4: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 3: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 2: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 1: --output; *output = (char)(input | FIRST_BYTE_MARK[*length]); } }
void TiXmlBase::EncodeString | ( | const TIXML_STRING & | str, |
TIXML_STRING * | out | ||
) | [static] |
Expands entities in a string. Note this should not contian the tag's '<', '>', etc, or they will be transformed into entities!
Definition at line 52 of file tinyxml.cpp.
{ int i=0; while( i<(int)str.length() ) { unsigned char c = (unsigned char) str[i]; if ( c == '&' && i < ( (int)str.length() - 2 ) && str[i+1] == '#' && str[i+2] == 'x' ) { // Hexadecimal character reference. // Pass through unchanged. // © -- copyright symbol, for example. // // The -1 is a bug fix from Rob Laveaux. It keeps // an overflow from happening if there is no ';'. // There are actually 2 ways to exit this loop - // while fails (error case) and break (semicolon found). // However, there is no mechanism (currently) for // this function to return an error. while ( i<(int)str.length()-1 ) { outString->append( str.c_str() + i, 1 ); ++i; if ( str[i] == ';' ) break; } } else if ( c == '&' ) { outString->append( entity[0].str, entity[0].strLength ); ++i; } else if ( c == '<' ) { outString->append( entity[1].str, entity[1].strLength ); ++i; } else if ( c == '>' ) { outString->append( entity[2].str, entity[2].strLength ); ++i; } else if ( c == '\"' ) { outString->append( entity[3].str, entity[3].strLength ); ++i; } else if ( c == '\'' ) { outString->append( entity[4].str, entity[4].strLength ); ++i; } else if ( c < 32 ) { // Easy pass at non-alpha/numeric/symbol // Below 32 is symbolic. char buf[ 32 ]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); #else sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); #endif //*ME: warning C4267: convert 'size_t' to 'int' //*ME: Int-Cast to make compiler happy ... outString->append( buf, (int)strlen( buf ) ); ++i; } else { //char realc = (char) c; //outString->append( &realc, 1 ); *outString += (char) c; // somewhat more efficient function call. ++i; } } }
static const char* TiXmlBase::GetChar | ( | const char * | p, |
char * | _value, | ||
int * | length, | ||
TiXmlEncoding | encoding | ||
) | [inline, static, protected] |
Definition at line 327 of file tinyxml.h.
{ assert( p ); if ( encoding == TIXML_ENCODING_UTF8 ) { *length = utf8ByteTable[ *((const unsigned char*)p) ]; assert( *length >= 0 && *length < 5 ); } else { *length = 1; } if ( *length == 1 ) { if ( *p == '&' ) return GetEntity( p, _value, length, encoding ); *_value = *p; return p+1; } else if ( *length ) { //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), // and the null terminator isn't needed for( int i=0; p[i] && i<*length; ++i ) { _value[i] = p[i]; } return p + (*length); } else { // Not valid text. return 0; } }
const char * TiXmlBase::GetEntity | ( | const char * | in, |
char * | value, | ||
int * | length, | ||
TiXmlEncoding | encoding | ||
) | [static, protected] |
Definition at line 438 of file tinyxmlparser.cpp.
{ // Presume an entity, and pull it out. TIXML_STRING ent; int i; *length = 0; if ( *(p+1) && *(p+1) == '#' && *(p+2) ) { unsigned long ucs = 0; ptrdiff_t delta = 0; unsigned mult = 1; if ( *(p+2) == 'x' ) { // Hexadecimal. if ( !*(p+3) ) return 0; const char* q = p+3; q = strchr( q, ';' ); if ( !q || !*q ) return 0; delta = q-p; --q; while ( *q != 'x' ) { if ( *q >= '0' && *q <= '9' ) ucs += mult * (*q - '0'); else if ( *q >= 'a' && *q <= 'f' ) ucs += mult * (*q - 'a' + 10); else if ( *q >= 'A' && *q <= 'F' ) ucs += mult * (*q - 'A' + 10 ); else return 0; mult *= 16; --q; } } else { // Decimal. if ( !*(p+2) ) return 0; const char* q = p+2; q = strchr( q, ';' ); if ( !q || !*q ) return 0; delta = q-p; --q; while ( *q != '#' ) { if ( *q >= '0' && *q <= '9' ) ucs += mult * (*q - '0'); else return 0; mult *= 10; --q; } } if ( encoding == TIXML_ENCODING_UTF8 ) { // convert the UCS to UTF-8 ConvertUTF32ToUTF8( ucs, value, length ); } else { *value = (char)ucs; *length = 1; } return p + delta + 1; } // Now try to match it. for( i=0; i<NUM_ENTITY; ++i ) { if ( strncmp( entity[i].str, p, entity[i].strLength ) == 0 ) { assert( strlen( entity[i].str ) == entity[i].strLength ); *value = entity[i].chr; *length = 1; return ( p + entity[i].strLength ); } } // So it wasn't an entity, its unrecognized, or something like that. *value = *p; // Don't put back the last one, since we return it! //*length = 1; // Leave unrecognized entities - this doesn't really work. // Just writes strange XML. return p+1; }
const void* TiXmlBase::GetUserData | ( | ) | const [inline] |
void* TiXmlBase::GetUserData | ( | ) | [inline] |
int TiXmlBase::IsAlpha | ( | unsigned char | anyByte, |
TiXmlEncoding | encoding | ||
) | [static, protected] |
Definition at line 129 of file tinyxmlparser.cpp.
{ // This will only work for low-ascii, everything else is assumed to be a valid // letter. I'm not sure this is the best approach, but it is quite tricky trying // to figure out alhabetical vs. not across encoding. So take a very // conservative approach. // if ( encoding == TIXML_ENCODING_UTF8 ) // { if ( anyByte < 127 ) return isalpha( anyByte ); else return 1; // What else to do? The unicode set is huge...get the english ones right. // } // else // { // return isalpha( anyByte ); // } }
int TiXmlBase::IsAlphaNum | ( | unsigned char | anyByte, |
TiXmlEncoding | encoding | ||
) | [static, protected] |
Definition at line 150 of file tinyxmlparser.cpp.
{ // This will only work for low-ascii, everything else is assumed to be a valid // letter. I'm not sure this is the best approach, but it is quite tricky trying // to figure out alhabetical vs. not across encoding. So take a very // conservative approach. // if ( encoding == TIXML_ENCODING_UTF8 ) // { if ( anyByte < 127 ) return isalnum( anyByte ); else return 1; // What else to do? The unicode set is huge...get the english ones right. // } // else // { // return isalnum( anyByte ); // } }
static bool TiXmlBase::IsWhiteSpace | ( | char | c | ) | [inline, static, protected] |
static bool TiXmlBase::IsWhiteSpace | ( | int | c | ) | [inline, static, protected] |
Definition at line 294 of file tinyxml.h.
{ if ( c < 256 ) return IsWhiteSpace( (char) c ); return false; // Again, only truly correct for English/Latin...but usually works. }
static bool TiXmlBase::IsWhiteSpaceCondensed | ( | ) | [inline, static] |
Return the current white space setting.
Definition at line 224 of file tinyxml.h.
{ return condenseWhiteSpace; }
void TiXmlBase::operator= | ( | const TiXmlBase & | base | ) | [private] |
virtual const char* TiXmlBase::Parse | ( | const char * | p, |
TiXmlParsingData * | data, | ||
TiXmlEncoding | encoding | ||
) | [pure virtual] |
Implemented in TiXmlAttribute, TiXmlElement, TiXmlComment, TiXmlText, TiXmlDeclaration, TiXmlUnknown, and TiXmlDocument.
virtual void TiXmlBase::Print | ( | FILE * | cfile, |
int | depth | ||
) | const [pure virtual] |
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.) Either or both cfile and str can be null.
This is a formatted print, and will insert tabs and newlines.
(For an unformatted stream, use the << operator.)
Implemented in TiXmlAttribute, TiXmlElement, TiXmlComment, TiXmlText, TiXmlDeclaration, TiXmlUnknown, and TiXmlDocument.
const char * TiXmlBase::ReadName | ( | const char * | p, |
TIXML_STRING * | name, | ||
TiXmlEncoding | encoding | ||
) | [static, protected] |
Definition at line 401 of file tinyxmlparser.cpp.
{ // Oddly, not supported on some comilers, //name->clear(); // So use this: *name = ""; assert( p ); // Names start with letters or underscores. // Of course, in unicode, tinyxml has no idea what a letter *is*. The // algorithm is generous. // // After that, they can be letters, underscores, numbers, // hyphens, or colons. (Colons are valid ony for namespaces, // but tinyxml can't tell namespaces from names.) if ( p && *p && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) { const char* start = p; while( p && *p && ( IsAlphaNum( (unsigned char ) *p, encoding ) || *p == '_' || *p == '-' || *p == '.' || *p == ':' ) ) { //(*name) += *p; // expensive ++p; } if ( p-start > 0 ) { name->assign( start, p-start ); } return p; } return 0; }
const char * TiXmlBase::ReadText | ( | const char * | in, |
TIXML_STRING * | text, | ||
bool | ignoreWhiteSpace, | ||
const char * | endTag, | ||
bool | ignoreCase, | ||
TiXmlEncoding | encoding | ||
) | [static, protected] |
Definition at line 574 of file tinyxmlparser.cpp.
{ *text = ""; if ( !trimWhiteSpace // certain tags always keep whitespace || !condenseWhiteSpace ) // if true, whitespace is always kept { // Keep all the white space. while ( p && *p && !StringEqual( p, endTag, caseInsensitive, encoding ) ) { int len; char cArr[4] = { 0, 0, 0, 0 }; p = GetChar( p, cArr, &len, encoding ); text->append( cArr, len ); } } else { bool whitespace = false; // Remove leading white space: p = SkipWhiteSpace( p, encoding ); while ( p && *p && !StringEqual( p, endTag, caseInsensitive, encoding ) ) { if ( *p == '\r' || *p == '\n' ) { whitespace = true; ++p; } else if ( IsWhiteSpace( *p ) ) { whitespace = true; ++p; } else { // If we've found whitespace, add it before the // new character. Any whitespace just becomes a space. if ( whitespace ) { (*text) += ' '; whitespace = false; } int len; char cArr[4] = { 0, 0, 0, 0 }; p = GetChar( p, cArr, &len, encoding ); if ( len == 1 ) (*text) += cArr[0]; // more efficient else text->append( cArr, len ); } } } if ( p && *p ) p += strlen( endTag ); return p; }
int TiXmlBase::Row | ( | ) | const [inline] |
Return the position, in the original source file, of this node or attribute. The row and column are 1-based. (That is the first row and first column is 1,1). If the returns values are 0 or less, then the parser does not have a row and column value.
Generally, the row and column value will be set when the TiXmlDocument::Load(), TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set when the DOM was created from operator>>.
The values reflect the initial load. Once the DOM is modified programmatically (by adding or changing nodes and attributes) the new values will NOT update to reflect changes in the document.
There is a minor performance cost to computing the row and column. Computation can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.
static void TiXmlBase::SetCondenseWhiteSpace | ( | bool | condense | ) | [inline, static] |
The world does not agree on whether white space should be kept or not. In order to make everyone happy, these global, static functions are provided to set whether or not TinyXml will condense all white space into a single space or not. The default is to condense. Note changing this value is not thread safe.
Definition at line 221 of file tinyxml.h.
{ condenseWhiteSpace = condense; }
void TiXmlBase::SetUserData | ( | void * | user | ) | [inline] |
const char * TiXmlBase::SkipWhiteSpace | ( | const char * | p, |
TiXmlEncoding | encoding | ||
) | [static, protected] |
Definition at line 314 of file tinyxmlparser.cpp.
{ if ( !p || !*p ) { return 0; } if ( encoding == TIXML_ENCODING_UTF8 ) { while ( *p ) { const unsigned char* pU = (const unsigned char*)p; // Skip the stupid Microsoft UTF-8 Byte order marks if ( *(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) { p += 3; continue; } else if(*(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==0xbfU && *(pU+2)==0xbeU ) { p += 3; continue; } else if(*(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==0xbfU && *(pU+2)==0xbfU ) { p += 3; continue; } if ( IsWhiteSpace( *p ) ) // Still using old rules for white space. ++p; else break; } } else { while ( *p && IsWhiteSpace( *p ) ) ++p; } return p; }
bool TiXmlBase::StringEqual | ( | const char * | p, |
const char * | endTag, | ||
bool | ignoreCase, | ||
TiXmlEncoding | encoding | ||
) | [static, protected] |
Definition at line 534 of file tinyxmlparser.cpp.
{ assert( p ); assert( tag ); if ( !p || !*p ) { assert( 0 ); return false; } const char* q = p; if ( ignoreCase ) { while ( *q && *tag && ToLower( *q, encoding ) == ToLower( *tag, encoding ) ) { ++q; ++tag; } if ( *tag == 0 ) return true; } else { while ( *q && *tag && *q == *tag ) { ++q; ++tag; } if ( *tag == 0 ) // Have we found the end of the tag, and everything equal? return true; } return false; }
static int TiXmlBase::ToLower | ( | int | v, |
TiXmlEncoding | encoding | ||
) | [inline, static, protected] |
Definition at line 382 of file tinyxml.h.
{ if ( encoding == TIXML_ENCODING_UTF8 ) { if ( v < 128 ) return tolower( v ); return v; } else { return tolower( v ); } }
friend class TiXmlDocument [friend] |
friend class TiXmlElement [friend] |
bool TiXmlBase::condenseWhiteSpace = true [static, private] |
TiXmlBase::Entity TiXmlBase::entity [static, private] |
const char * TiXmlBase::errorString [static, protected] |
{ "No error", "Error", "Failed to open file", "Error parsing Element.", "Failed to read Element name", "Error reading Element value.", "Error reading Attributes.", "Error: empty tag.", "Error reading end tag.", "Error parsing Unknown.", "Error parsing Comment.", "Error parsing Declaration.", "Error document empty.", "Error null (0) or unexpected EOF found in input stream.", "Error parsing CDATA.", "Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.", }
TiXmlCursor TiXmlBase::location [protected] |
void* TiXmlBase::userData [protected] |
const int TiXmlBase::utf8ByteTable [static] |
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }