#include <OBTtinyxml.h>
Public Types | |
enum | { TIXML_NO_ERROR = 0, TIXML_ERROR, TIXML_ERROR_OPENING_FILE, TIXML_ERROR_OUT_OF_MEMORY, 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 } |
enum | { TIXML_NO_ERROR = 0, TIXML_ERROR, TIXML_ERROR_OPENING_FILE, TIXML_ERROR_OUT_OF_MEMORY, 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 |
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode. | |
int | Row () const |
Return the position, in the original source file, of this node or attribute. | |
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 |
TiXmlBase () | |
virtual | ~TiXmlBase () |
virtual void | Print (FILE *cfile, int depth) const =0 |
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode. | |
int | Row () const |
Return the position, in the original source file, of this node or attribute. | |
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) |
The world does not agree on whether white space should be kept or not. | |
static bool | IsWhiteSpaceCondensed () |
Return the current white space setting. | |
static void | EncodeString (const TIXML_STRING &str, TIXML_STRING *out) |
Expands entities in a string. | |
static void | SetCondenseWhiteSpace (bool condense) |
The world does not agree on whether white space should be kept or not. | |
static bool | IsWhiteSpaceCondensed () |
Return the current white space setting. | |
static void | EncodeString (const TIXML_STRING &str, TIXML_STRING *out) |
Expands entities in a string. | |
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 bool | StreamWhiteSpace (std::istream *in, TIXML_STRING *tag) |
static bool | StreamTo (std::istream *in, int character, TIXML_STRING *tag) |
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) |
static const char * | SkipWhiteSpace (const char *, TiXmlEncoding encoding) |
static bool | IsWhiteSpace (char c) |
static bool | IsWhiteSpace (int c) |
static bool | StreamWhiteSpace (std::istream *in, TIXML_STRING *tag) |
static bool | StreamTo (std::istream *in, int character, TIXML_STRING *tag) |
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. | |
void * | userData |
Field containing a generic user pointer. | |
Static Protected Attributes | |
static const char * | errorString [TIXML_ERROR_STRING_COUNT] |
static const char * | errorString [TIXML_ERROR_STRING_COUNT] |
Private Types | |
enum | { NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6 } |
enum | { NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6 } |
Private Member Functions | |
TiXmlBase (const TiXmlBase &) | |
void | operator= (const TiXmlBase &base) |
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 |
Classes | |
struct | Entity |
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)
Definition at line 203 of file OBTtinyxml.h.
anonymous enum |
Definition at line 273 of file OBTtinyxml.h.
00274 { 00275 TIXML_NO_ERROR = 0, 00276 TIXML_ERROR, 00277 TIXML_ERROR_OPENING_FILE, 00278 TIXML_ERROR_OUT_OF_MEMORY, 00279 TIXML_ERROR_PARSING_ELEMENT, 00280 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, 00281 TIXML_ERROR_READING_ELEMENT_VALUE, 00282 TIXML_ERROR_READING_ATTRIBUTES, 00283 TIXML_ERROR_PARSING_EMPTY, 00284 TIXML_ERROR_READING_END_TAG, 00285 TIXML_ERROR_PARSING_UNKNOWN, 00286 TIXML_ERROR_PARSING_COMMENT, 00287 TIXML_ERROR_PARSING_DECLARATION, 00288 TIXML_ERROR_DOCUMENT_EMPTY, 00289 TIXML_ERROR_EMBEDDED_NULL, 00290 TIXML_ERROR_PARSING_CDATA, 00291 TIXML_ERROR_DOCUMENT_TOP_ONLY, 00292 00293 TIXML_ERROR_STRING_COUNT 00294 };
anonymous enum [private] |
Definition at line 415 of file OBTtinyxml.h.
00416 { 00417 NUM_ENTITY = 5, 00418 MAX_ENTITY_LENGTH = 6 00419 00420 };
anonymous enum |
Definition at line 272 of file tiny/OBTtinyxml.h.
00273 { 00274 TIXML_NO_ERROR = 0, 00275 TIXML_ERROR, 00276 TIXML_ERROR_OPENING_FILE, 00277 TIXML_ERROR_OUT_OF_MEMORY, 00278 TIXML_ERROR_PARSING_ELEMENT, 00279 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, 00280 TIXML_ERROR_READING_ELEMENT_VALUE, 00281 TIXML_ERROR_READING_ATTRIBUTES, 00282 TIXML_ERROR_PARSING_EMPTY, 00283 TIXML_ERROR_READING_END_TAG, 00284 TIXML_ERROR_PARSING_UNKNOWN, 00285 TIXML_ERROR_PARSING_COMMENT, 00286 TIXML_ERROR_PARSING_DECLARATION, 00287 TIXML_ERROR_DOCUMENT_EMPTY, 00288 TIXML_ERROR_EMBEDDED_NULL, 00289 TIXML_ERROR_PARSING_CDATA, 00290 TIXML_ERROR_DOCUMENT_TOP_ONLY, 00291 00292 TIXML_ERROR_STRING_COUNT 00293 };
anonymous enum [private] |
Definition at line 414 of file tiny/OBTtinyxml.h.
00415 { 00416 NUM_ENTITY = 5, 00417 MAX_ENTITY_LENGTH = 6 00418 00419 };
OBT::TiXmlBase::TiXmlBase | ( | ) | [inline] |
virtual OBT::TiXmlBase::~TiXmlBase | ( | ) | [inline, virtual] |
OBT::TiXmlBase::TiXmlBase | ( | const TiXmlBase & | ) | [private] |
OBT::TiXmlBase::TiXmlBase | ( | ) | [inline] |
virtual OBT::TiXmlBase::~TiXmlBase | ( | ) | [inline, virtual] |
OBT::TiXmlBase::TiXmlBase | ( | const TiXmlBase & | ) | [private] |
virtual void OBT::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 OBT::TiXmlAttribute, OBT::TiXmlElement, OBT::TiXmlComment, OBT::TiXmlText, OBT::TiXmlDeclaration, OBT::TiXmlUnknown, OBT::TiXmlDocument, OBT::TiXmlAttribute, OBT::TiXmlElement, OBT::TiXmlComment, OBT::TiXmlText, OBT::TiXmlDeclaration, OBT::TiXmlUnknown, and OBT::TiXmlDocument.
Referenced by OBT::TiXmlElement::Print().
static void OBT::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 230 of file OBTtinyxml.h.
00230 { condenseWhiteSpace = condense; }
static bool OBT::TiXmlBase::IsWhiteSpaceCondensed | ( | ) | [inline, static] |
Return the current white space setting.
Definition at line 233 of file OBTtinyxml.h.
Referenced by OBT::TiXmlElement::ReadValue().
00233 { return condenseWhiteSpace; }
int OBT::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.
Definition at line 253 of file OBTtinyxml.h.
00253 { return location.row + 1; }
int OBT::TiXmlBase::Column | ( | ) | const [inline] |
void OBT::TiXmlBase::SetUserData | ( | void * | user | ) | [inline] |
void* OBT::TiXmlBase::GetUserData | ( | ) | [inline] |
const void* OBT::TiXmlBase::GetUserData | ( | ) | const [inline] |
virtual const char* OBT::TiXmlBase::Parse | ( | const char * | p, | |
TiXmlParsingData * | data, | |||
TiXmlEncoding | encoding | |||
) | [pure virtual] |
Implemented in OBT::TiXmlAttribute, OBT::TiXmlElement, OBT::TiXmlComment, OBT::TiXmlText, OBT::TiXmlDeclaration, OBT::TiXmlUnknown, OBT::TiXmlDocument, OBT::TiXmlAttribute, OBT::TiXmlElement, OBT::TiXmlComment, OBT::TiXmlText, OBT::TiXmlDeclaration, OBT::TiXmlUnknown, and OBT::TiXmlDocument.
Referenced by OBT::operator>>(), OBT::TiXmlDocument::Parse(), and OBT::TiXmlElement::ReadValue().
void OBT::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 53 of file OBTtinyxml.cpp.
References entity.
Referenced by OBT::TiXmlText::Print(), OBT::TiXmlAttribute::Print(), and OBT::TiXmlPrinter::Visit().
00054 { 00055 int i=0; 00056 00057 while( i<(int)str.length() ) 00058 { 00059 unsigned char c = (unsigned char) str[i]; 00060 00061 if ( c == '&' 00062 && i < ( (int)str.length() - 2 ) 00063 && str[i+1] == '#' 00064 && str[i+2] == 'x' ) 00065 { 00066 // Hexadecimal character reference. 00067 // Pass through unchanged. 00068 // © -- copyright symbol, for example. 00069 // 00070 // The -1 is a bug fix from Rob Laveaux. It keeps 00071 // an overflow from happening if there is no ';'. 00072 // There are actually 2 ways to exit this loop - 00073 // while fails (error case) and break (semicolon found). 00074 // However, there is no mechanism (currently) for 00075 // this function to return an error. 00076 while ( i<(int)str.length()-1 ) 00077 { 00078 outString->append( str.c_str() + i, 1 ); 00079 ++i; 00080 if ( str[i] == ';' ) 00081 break; 00082 } 00083 } 00084 else if ( c == '&' ) 00085 { 00086 outString->append( entity[0].str, entity[0].strLength ); 00087 ++i; 00088 } 00089 else if ( c == '<' ) 00090 { 00091 outString->append( entity[1].str, entity[1].strLength ); 00092 ++i; 00093 } 00094 else if ( c == '>' ) 00095 { 00096 outString->append( entity[2].str, entity[2].strLength ); 00097 ++i; 00098 } 00099 else if ( c == '\"' ) 00100 { 00101 outString->append( entity[3].str, entity[3].strLength ); 00102 ++i; 00103 } 00104 else if ( c == '\'' ) 00105 { 00106 outString->append( entity[4].str, entity[4].strLength ); 00107 ++i; 00108 } 00109 else if ( c < 32 ) 00110 { 00111 // Easy pass at non-alpha/numeric/symbol 00112 // Below 32 is symbolic. 00113 char buf[ 32 ]; 00114 00115 #if defined(TIXML_SNPRINTF) 00116 TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); 00117 #else 00118 sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); 00119 #endif 00120 00121 //*ME: warning C4267: convert 'size_t' to 'int' 00122 //*ME: Int-Cast to make compiler happy ... 00123 outString->append( buf, (int)strlen( buf ) ); 00124 ++i; 00125 } 00126 else 00127 { 00128 //char realc = (char) c; 00129 //outString->append( &realc, 1 ); 00130 *outString += (char) c; // somewhat more efficient function call. 00131 ++i; 00132 } 00133 } 00134 }
const char * OBT::TiXmlBase::SkipWhiteSpace | ( | const char * | p, | |
TiXmlEncoding | encoding | |||
) | [static, protected] |
Definition at line 316 of file OBTtinyxmlparser.cpp.
References IsWhiteSpace(), OBT::TIXML_ENCODING_UTF8, OBT::TIXML_UTF_LEAD_0, OBT::TIXML_UTF_LEAD_1, and OBT::TIXML_UTF_LEAD_2.
Referenced by OBT::TiXmlNode::Identify(), OBT::TiXmlDeclaration::Parse(), OBT::TiXmlAttribute::Parse(), OBT::TiXmlComment::Parse(), OBT::TiXmlUnknown::Parse(), OBT::TiXmlElement::Parse(), OBT::TiXmlDocument::Parse(), ReadText(), and OBT::TiXmlElement::ReadValue().
00317 { 00318 if ( !p || !*p ) 00319 { 00320 return 0; 00321 } 00322 if ( encoding == TIXML_ENCODING_UTF8 ) 00323 { 00324 while ( *p ) 00325 { 00326 const unsigned char* pU = (const unsigned char*)p; 00327 00328 // Skip the stupid Microsoft UTF-8 Byte order marks 00329 if ( *(pU+0)==TIXML_UTF_LEAD_0 00330 && *(pU+1)==TIXML_UTF_LEAD_1 00331 && *(pU+2)==TIXML_UTF_LEAD_2 ) 00332 { 00333 p += 3; 00334 continue; 00335 } 00336 else if(*(pU+0)==TIXML_UTF_LEAD_0 00337 && *(pU+1)==0xbfU 00338 && *(pU+2)==0xbeU ) 00339 { 00340 p += 3; 00341 continue; 00342 } 00343 else if(*(pU+0)==TIXML_UTF_LEAD_0 00344 && *(pU+1)==0xbfU 00345 && *(pU+2)==0xbfU ) 00346 { 00347 p += 3; 00348 continue; 00349 } 00350 00351 if ( IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. 00352 ++p; 00353 else 00354 break; 00355 } 00356 } 00357 else 00358 { 00359 while ( *p && IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ) 00360 ++p; 00361 } 00362 00363 return p; 00364 }
static bool OBT::TiXmlBase::IsWhiteSpace | ( | char | c | ) | [inline, static, protected] |
Definition at line 299 of file OBTtinyxml.h.
Referenced by OBT::TiXmlText::Blank(), IsWhiteSpace(), OBT::TiXmlDeclaration::Parse(), OBT::TiXmlAttribute::Parse(), ReadText(), SkipWhiteSpace(), OBT::TiXmlElement::StreamIn(), and StreamWhiteSpace().
static bool OBT::TiXmlBase::IsWhiteSpace | ( | int | c | ) | [inline, static, protected] |
Definition at line 303 of file OBTtinyxml.h.
00304 { 00305 if ( c < 256 ) 00306 return IsWhiteSpace( (char) c ); 00307 return false; // Again, only truly correct for English/Latin...but usually works. 00308 }
bool OBT::TiXmlBase::StreamWhiteSpace | ( | std::istream * | in, | |
TIXML_STRING * | tag | |||
) | [static, protected] |
Definition at line 367 of file OBTtinyxmlparser.cpp.
References IsWhiteSpace().
Referenced by OBT::TiXmlElement::StreamIn().
00368 { 00369 for( ;; ) 00370 { 00371 if ( !in->good() ) return false; 00372 00373 int c = in->peek(); 00374 // At this scope, we can't get to a document. So fail silently. 00375 if ( !IsWhiteSpace( c ) || c <= 0 ) 00376 return true; 00377 00378 *tag += (char) in->get(); 00379 } 00380 }
bool OBT::TiXmlBase::StreamTo | ( | std::istream * | in, | |
int | character, | |||
TIXML_STRING * | tag | |||
) | [static, protected] |
Definition at line 382 of file OBTtinyxmlparser.cpp.
Referenced by OBT::TiXmlDocument::StreamIn().
00383 { 00384 //assert( character > 0 && character < 128 ); // else it won't work in utf-8 00385 while ( in->good() ) 00386 { 00387 int c = in->peek(); 00388 if ( c == character ) 00389 return true; 00390 if ( c <= 0 ) // Silent failure: can't get document at this scope 00391 return false; 00392 00393 in->get(); 00394 *tag += (char) c; 00395 } 00396 return false; 00397 }
const char * OBT::TiXmlBase::ReadName | ( | const char * | p, | |
TIXML_STRING * | name, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
Definition at line 403 of file OBTtinyxmlparser.cpp.
References IsAlpha(), and IsAlphaNum().
Referenced by OBT::TiXmlAttribute::Parse(), and OBT::TiXmlElement::Parse().
00404 { 00405 // Oddly, not supported on some comilers, 00406 //name->clear(); 00407 // So use this: 00408 *name = ""; 00409 assert( p ); 00410 00411 // Names start with letters or underscores. 00412 // Of course, in unicode, OBTtinyxml.has no idea what a letter *is*. The 00413 // algorithm is generous. 00414 // 00415 // After that, they can be letters, underscores, numbers, 00416 // hyphens, or colons. (Colons are valid ony for namespaces, 00417 // but tinyxml can't tell namespaces from names.) 00418 if ( p && *p 00419 && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) 00420 { 00421 const char* start = p; 00422 while( p && *p 00423 && ( IsAlphaNum( (unsigned char ) *p, encoding ) 00424 || *p == '_' 00425 || *p == '-' 00426 || *p == '.' 00427 || *p == ':' ) ) 00428 { 00429 //(*name) += *p; // expensive 00430 ++p; 00431 } 00432 if ( p-start > 0 ) { 00433 name->assign( start, p-start ); 00434 } 00435 return p; 00436 } 00437 return 0; 00438 }
const char * OBT::TiXmlBase::ReadText | ( | const char * | in, | |
TIXML_STRING * | text, | |||
bool | ignoreWhiteSpace, | |||
const char * | endTag, | |||
bool | ignoreCase, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
Definition at line 576 of file OBTtinyxmlparser.cpp.
References condenseWhiteSpace, GetChar(), IsWhiteSpace(), SkipWhiteSpace(), and StringEqual().
Referenced by OBT::TiXmlText::Parse(), and OBT::TiXmlAttribute::Parse().
00582 { 00583 *text = ""; 00584 if ( !trimWhiteSpace // certain tags always keep whitespace 00585 || !condenseWhiteSpace ) // if true, whitespace is always kept 00586 { 00587 // Keep all the white space. 00588 while ( p && *p 00589 && !StringEqual( p, endTag, caseInsensitive, encoding ) 00590 ) 00591 { 00592 int len; 00593 char cArr[4] = { 0, 0, 0, 0 }; 00594 p = GetChar( p, cArr, &len, encoding ); 00595 text->append( cArr, len ); 00596 } 00597 } 00598 else 00599 { 00600 bool whitespace = false; 00601 00602 // Remove leading white space: 00603 p = SkipWhiteSpace( p, encoding ); 00604 while ( p && *p 00605 && !StringEqual( p, endTag, caseInsensitive, encoding ) ) 00606 { 00607 if ( *p == '\r' || *p == '\n' ) 00608 { 00609 whitespace = true; 00610 ++p; 00611 } 00612 else if ( IsWhiteSpace( *p ) ) 00613 { 00614 whitespace = true; 00615 ++p; 00616 } 00617 else 00618 { 00619 // If we've found whitespace, add it before the 00620 // new character. Any whitespace just becomes a space. 00621 if ( whitespace ) 00622 { 00623 (*text) += ' '; 00624 whitespace = false; 00625 } 00626 int len; 00627 char cArr[4] = { 0, 0, 0, 0 }; 00628 p = GetChar( p, cArr, &len, encoding ); 00629 if ( len == 1 ) 00630 (*text) += cArr[0]; // more efficient 00631 else 00632 text->append( cArr, len ); 00633 } 00634 } 00635 } 00636 if ( p ) 00637 p += strlen( endTag ); 00638 return p; 00639 }
const char * OBT::TiXmlBase::GetEntity | ( | const char * | in, | |
char * | value, | |||
int * | length, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
Definition at line 440 of file OBTtinyxmlparser.cpp.
References OBT::TiXmlBase::Entity::chr, ConvertUTF32ToUTF8(), entity, NUM_ENTITY, OBT::TIXML_ENCODING_UTF8, and TIXML_STRING.
Referenced by GetChar().
00441 { 00442 // Presume an entity, and pull it out. 00443 TIXML_STRING ent; 00444 int i; 00445 *length = 0; 00446 00447 if ( *(p+1) && *(p+1) == '#' && *(p+2) ) 00448 { 00449 unsigned long ucs = 0; 00450 ptrdiff_t delta = 0; 00451 unsigned mult = 1; 00452 00453 if ( *(p+2) == 'x' ) 00454 { 00455 // Hexadecimal. 00456 if ( !*(p+3) ) return 0; 00457 00458 const char* q = p+3; 00459 q = strchr( q, ';' ); 00460 00461 if ( !q || !*q ) return 0; 00462 00463 delta = q-p; 00464 --q; 00465 00466 while ( *q != 'x' ) 00467 { 00468 if ( *q >= '0' && *q <= '9' ) 00469 ucs += mult * (*q - '0'); 00470 else if ( *q >= 'a' && *q <= 'f' ) 00471 ucs += mult * (*q - 'a' + 10); 00472 else if ( *q >= 'A' && *q <= 'F' ) 00473 ucs += mult * (*q - 'A' + 10 ); 00474 else 00475 return 0; 00476 mult *= 16; 00477 --q; 00478 } 00479 } 00480 else 00481 { 00482 // Decimal. 00483 if ( !*(p+2) ) return 0; 00484 00485 const char* q = p+2; 00486 q = strchr( q, ';' ); 00487 00488 if ( !q || !*q ) return 0; 00489 00490 delta = q-p; 00491 --q; 00492 00493 while ( *q != '#' ) 00494 { 00495 if ( *q >= '0' && *q <= '9' ) 00496 ucs += mult * (*q - '0'); 00497 else 00498 return 0; 00499 mult *= 10; 00500 --q; 00501 } 00502 } 00503 if ( encoding == TIXML_ENCODING_UTF8 ) 00504 { 00505 // convert the UCS to UTF-8 00506 ConvertUTF32ToUTF8( ucs, value, length ); 00507 } 00508 else 00509 { 00510 *value = (char)ucs; 00511 *length = 1; 00512 } 00513 return p + delta + 1; 00514 } 00515 00516 // Now try to match it. 00517 for( i=0; i<NUM_ENTITY; ++i ) 00518 { 00519 if ( strncmp( entity[i].str, p, entity[i].strLength ) == 0 ) 00520 { 00521 assert( strlen( entity[i].str ) == entity[i].strLength ); 00522 *value = entity[i].chr; 00523 *length = 1; 00524 return ( p + entity[i].strLength ); 00525 } 00526 } 00527 00528 // So it wasn't an entity, its unrecognized, or something like that. 00529 *value = *p; // Don't put back the last one, since we return it! 00530 //*length = 1; // Leave unrecognized entities - this doesn't really work. 00531 // Just writes strange XML. 00532 return p+1; 00533 }
static const char* OBT::TiXmlBase::GetChar | ( | const char * | p, | |
char * | _value, | |||
int * | length, | |||
TiXmlEncoding | encoding | |||
) | [inline, static, protected] |
Definition at line 336 of file OBTtinyxml.h.
References OBT::TIXML_ENCODING_UTF8.
Referenced by ReadText().
00337 { 00338 assert( p ); 00339 if ( encoding == TIXML_ENCODING_UTF8 ) 00340 { 00341 *length = utf8ByteTable[ *((const unsigned char*)p) ]; 00342 assert( *length >= 0 && *length < 5 ); 00343 } 00344 else 00345 { 00346 *length = 1; 00347 } 00348 00349 if ( *length == 1 ) 00350 { 00351 if ( *p == '&' ) 00352 return GetEntity( p, _value, length, encoding ); 00353 *_value = *p; 00354 return p+1; 00355 } 00356 else if ( *length ) 00357 { 00358 //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), 00359 // and the null terminator isn't needed 00360 for( int i=0; p[i] && i<*length; ++i ) { 00361 _value[i] = p[i]; 00362 } 00363 return p + (*length); 00364 } 00365 else 00366 { 00367 // Not valid text. 00368 return 0; 00369 } 00370 }
bool OBT::TiXmlBase::StringEqual | ( | const char * | p, | |
const char * | endTag, | |||
bool | ignoreCase, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
Definition at line 536 of file OBTtinyxmlparser.cpp.
References ToLower().
Referenced by OBT::TiXmlNode::Identify(), OBT::TiXmlDeclaration::Parse(), OBT::TiXmlText::Parse(), OBT::TiXmlComment::Parse(), OBT::TiXmlElement::Parse(), OBT::TiXmlDocument::Parse(), ReadText(), and OBT::TiXmlElement::ReadValue().
00540 { 00541 assert( p ); 00542 assert( tag ); 00543 if ( !p || !*p ) 00544 { 00545 assert( 0 ); 00546 return false; 00547 } 00548 00549 const char* q = p; 00550 00551 if ( ignoreCase ) 00552 { 00553 while ( *q && *tag && ToLower( *q, encoding ) == ToLower( *tag, encoding ) ) 00554 { 00555 ++q; 00556 ++tag; 00557 } 00558 00559 if ( *tag == 0 ) 00560 return true; 00561 } 00562 else 00563 { 00564 while ( *q && *tag && *q == *tag ) 00565 { 00566 ++q; 00567 ++tag; 00568 } 00569 00570 if ( *tag == 0 ) // Have we found the end of the tag, and everything equal? 00571 return true; 00572 } 00573 return false; 00574 }
int OBT::TiXmlBase::IsAlpha | ( | unsigned char | anyByte, | |
TiXmlEncoding | encoding | |||
) | [static, protected] |
Definition at line 131 of file OBTtinyxmlparser.cpp.
Referenced by OBT::TiXmlNode::Identify(), and ReadName().
00132 { 00133 // This will only work for low-ascii, everything else is assumed to be a valid 00134 // letter. I'm not sure this is the best approach, but it is quite tricky trying 00135 // to figure out alhabetical vs. not across encoding. So take a very 00136 // conservative approach. 00137 00138 // if ( encoding == TIXML_ENCODING_UTF8 ) 00139 // { 00140 if ( anyByte < 127 ) 00141 return isalpha( anyByte ); 00142 else 00143 return 1; // What else to do? The unicode set is huge...get the english ones right. 00144 // } 00145 // else 00146 // { 00147 // return isalpha( anyByte ); 00148 // } 00149 }
int OBT::TiXmlBase::IsAlphaNum | ( | unsigned char | anyByte, | |
TiXmlEncoding | encoding | |||
) | [static, protected] |
Definition at line 152 of file OBTtinyxmlparser.cpp.
Referenced by ReadName().
00153 { 00154 // This will only work for low-ascii, everything else is assumed to be a valid 00155 // letter. I'm not sure this is the best approach, but it is quite tricky trying 00156 // to figure out alhabetical vs. not across encoding. So take a very 00157 // conservative approach. 00158 00159 // if ( encoding == TIXML_ENCODING_UTF8 ) 00160 // { 00161 if ( anyByte < 127 ) 00162 return isalnum( anyByte ); 00163 else 00164 return 1; // What else to do? The unicode set is huge...get the english ones right. 00165 // } 00166 // else 00167 // { 00168 // return isalnum( anyByte ); 00169 // } 00170 }
static int OBT::TiXmlBase::ToLower | ( | int | v, | |
TiXmlEncoding | encoding | |||
) | [inline, static, protected] |
Definition at line 391 of file OBTtinyxml.h.
References OBT::TIXML_ENCODING_UTF8.
Referenced by StringEqual().
00392 { 00393 if ( encoding == TIXML_ENCODING_UTF8 ) 00394 { 00395 if ( v < 128 ) return tolower( v ); 00396 return v; 00397 } 00398 else 00399 { 00400 return tolower( v ); 00401 } 00402 }
void OBT::TiXmlBase::ConvertUTF32ToUTF8 | ( | unsigned long | input, | |
char * | output, | |||
int * | length | |||
) | [static, protected] |
Definition at line 90 of file OBTtinyxmlparser.cpp.
Referenced by GetEntity().
00091 { 00092 const unsigned long BYTE_MASK = 0xBF; 00093 const unsigned long BYTE_MARK = 0x80; 00094 const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; 00095 00096 if (input < 0x80) 00097 *length = 1; 00098 else if ( input < 0x800 ) 00099 *length = 2; 00100 else if ( input < 0x10000 ) 00101 *length = 3; 00102 else if ( input < 0x200000 ) 00103 *length = 4; 00104 else 00105 { *length = 0; return; } // This code won't covert this correctly anyway. 00106 00107 output += *length; 00108 00109 // Scary scary fall throughs. 00110 switch (*length) 00111 { 00112 case 4: 00113 --output; 00114 *output = (char)((input | BYTE_MARK) & BYTE_MASK); 00115 input >>= 6; 00116 case 3: 00117 --output; 00118 *output = (char)((input | BYTE_MARK) & BYTE_MASK); 00119 input >>= 6; 00120 case 2: 00121 --output; 00122 *output = (char)((input | BYTE_MARK) & BYTE_MASK); 00123 input >>= 6; 00124 case 1: 00125 --output; 00126 *output = (char)(input | FIRST_BYTE_MARK[*length]); 00127 } 00128 }
void OBT::TiXmlBase::operator= | ( | const TiXmlBase & | base | ) | [private] |
virtual void OBT::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 OBT::TiXmlAttribute, OBT::TiXmlElement, OBT::TiXmlComment, OBT::TiXmlText, OBT::TiXmlDeclaration, OBT::TiXmlUnknown, OBT::TiXmlDocument, OBT::TiXmlAttribute, OBT::TiXmlElement, OBT::TiXmlComment, OBT::TiXmlText, OBT::TiXmlDeclaration, OBT::TiXmlUnknown, and OBT::TiXmlDocument.
static void OBT::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 229 of file tiny/OBTtinyxml.h.
References condenseWhiteSpace.
00229 { condenseWhiteSpace = condense; }
static bool OBT::TiXmlBase::IsWhiteSpaceCondensed | ( | ) | [inline, static] |
Return the current white space setting.
Definition at line 232 of file tiny/OBTtinyxml.h.
References condenseWhiteSpace.
00232 { return condenseWhiteSpace; }
int OBT::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.
Definition at line 252 of file tiny/OBTtinyxml.h.
References location, and OBT::TiXmlCursor::row.
00252 { return location.row + 1; }
int OBT::TiXmlBase::Column | ( | ) | const [inline] |
See Row().
Definition at line 253 of file tiny/OBTtinyxml.h.
References OBT::TiXmlCursor::col, and location.
void OBT::TiXmlBase::SetUserData | ( | void * | user | ) | [inline] |
Set a pointer to arbitrary user data.
Definition at line 255 of file tiny/OBTtinyxml.h.
References userData.
void* OBT::TiXmlBase::GetUserData | ( | ) | [inline] |
Get a pointer to arbitrary user data.
Definition at line 256 of file tiny/OBTtinyxml.h.
References userData.
const void* OBT::TiXmlBase::GetUserData | ( | ) | const [inline] |
Get a pointer to arbitrary user data.
Definition at line 257 of file tiny/OBTtinyxml.h.
References userData.
virtual const char* OBT::TiXmlBase::Parse | ( | const char * | p, | |
TiXmlParsingData * | data, | |||
TiXmlEncoding | encoding | |||
) | [pure virtual] |
static void OBT::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!
static const char* OBT::TiXmlBase::SkipWhiteSpace | ( | const char * | , | |
TiXmlEncoding | encoding | |||
) | [static, protected] |
static bool OBT::TiXmlBase::IsWhiteSpace | ( | char | c | ) | [inline, static, protected] |
static bool OBT::TiXmlBase::IsWhiteSpace | ( | int | c | ) | [inline, static, protected] |
Definition at line 302 of file tiny/OBTtinyxml.h.
References IsWhiteSpace().
00303 { 00304 if ( c < 256 ) 00305 return IsWhiteSpace( (char) c ); 00306 return false; // Again, only truly correct for English/Latin...but usually works. 00307 }
static bool OBT::TiXmlBase::StreamWhiteSpace | ( | std::istream * | in, | |
TIXML_STRING * | tag | |||
) | [static, protected] |
static bool OBT::TiXmlBase::StreamTo | ( | std::istream * | in, | |
int | character, | |||
TIXML_STRING * | tag | |||
) | [static, protected] |
static const char* OBT::TiXmlBase::ReadName | ( | const char * | p, | |
TIXML_STRING * | name, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
static const char* OBT::TiXmlBase::ReadText | ( | const char * | in, | |
TIXML_STRING * | text, | |||
bool | ignoreWhiteSpace, | |||
const char * | endTag, | |||
bool | ignoreCase, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
static const char* OBT::TiXmlBase::GetEntity | ( | const char * | in, | |
char * | value, | |||
int * | length, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
static const char* OBT::TiXmlBase::GetChar | ( | const char * | p, | |
char * | _value, | |||
int * | length, | |||
TiXmlEncoding | encoding | |||
) | [inline, static, protected] |
Definition at line 335 of file tiny/OBTtinyxml.h.
References GetEntity(), OBT::TIXML_ENCODING_UTF8, and utf8ByteTable.
00336 { 00337 assert( p ); 00338 if ( encoding == TIXML_ENCODING_UTF8 ) 00339 { 00340 *length = utf8ByteTable[ *((const unsigned char*)p) ]; 00341 assert( *length >= 0 && *length < 5 ); 00342 } 00343 else 00344 { 00345 *length = 1; 00346 } 00347 00348 if ( *length == 1 ) 00349 { 00350 if ( *p == '&' ) 00351 return GetEntity( p, _value, length, encoding ); 00352 *_value = *p; 00353 return p+1; 00354 } 00355 else if ( *length ) 00356 { 00357 //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), 00358 // and the null terminator isn't needed 00359 for( int i=0; p[i] && i<*length; ++i ) { 00360 _value[i] = p[i]; 00361 } 00362 return p + (*length); 00363 } 00364 else 00365 { 00366 // Not valid text. 00367 return 0; 00368 } 00369 }
static bool OBT::TiXmlBase::StringEqual | ( | const char * | p, | |
const char * | endTag, | |||
bool | ignoreCase, | |||
TiXmlEncoding | encoding | |||
) | [static, protected] |
static int OBT::TiXmlBase::IsAlpha | ( | unsigned char | anyByte, | |
TiXmlEncoding | encoding | |||
) | [static, protected] |
static int OBT::TiXmlBase::IsAlphaNum | ( | unsigned char | anyByte, | |
TiXmlEncoding | encoding | |||
) | [static, protected] |
static int OBT::TiXmlBase::ToLower | ( | int | v, | |
TiXmlEncoding | encoding | |||
) | [inline, static, protected] |
Definition at line 390 of file tiny/OBTtinyxml.h.
References OBT::TIXML_ENCODING_UTF8.
00391 { 00392 if ( encoding == TIXML_ENCODING_UTF8 ) 00393 { 00394 if ( v < 128 ) return tolower( v ); 00395 return v; 00396 } 00397 else 00398 { 00399 return tolower( v ); 00400 } 00401 }
static void OBT::TiXmlBase::ConvertUTF32ToUTF8 | ( | unsigned long | input, | |
char * | output, | |||
int * | length | |||
) | [static, protected] |
void OBT::TiXmlBase::operator= | ( | const TiXmlBase & | base | ) | [private] |
TiXmlNode [friend] |
Definition at line 205 of file OBTtinyxml.h.
TiXmlElement [friend] |
TiXmlDocument [friend] |
const int OBT::TiXmlBase::utf8ByteTable [static] |
Initial value:
{ 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 }
Definition at line 262 of file OBTtinyxml.h.
Referenced by GetChar(), and OBT::TiXmlParsingData::Stamp().
const char * OBT::TiXmlBase::errorString [static, protected] |
Initial value:
{ "No error", "Error", "Failed to open file", "Memory allocation failed.", "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.", }
Definition at line 380 of file OBTtinyxml.h.
Referenced by OBT::TiXmlDocument::SetError().
TiXmlCursor OBT::TiXmlBase::location [protected] |
Definition at line 382 of file OBTtinyxml.h.
Referenced by Column(), OBT::TiXmlDocument::LoadFile(), OBT::TiXmlDeclaration::Parse(), OBT::TiXmlText::Parse(), OBT::TiXmlAttribute::Parse(), OBT::TiXmlComment::Parse(), OBT::TiXmlUnknown::Parse(), OBT::TiXmlElement::Parse(), OBT::TiXmlDocument::Parse(), and Row().
void* OBT::TiXmlBase::userData [protected] |
Field containing a generic user pointer.
Definition at line 385 of file OBTtinyxml.h.
Referenced by OBT::TiXmlNode::CopyTo(), GetUserData(), and SetUserData().
TiXmlBase::Entity OBT::TiXmlBase::entity [static, private] |
Initial value:
{ { "&", 5, '&' }, { "<", 4, '<' }, { ">", 4, '>' }, { """, 6, '\"' }, { "'", 6, '\'' } }
Definition at line 421 of file OBTtinyxml.h.
Referenced by EncodeString(), and GetEntity().
static bool OBT::TiXmlBase::condenseWhiteSpace = true [static, private] |
Definition at line 422 of file OBTtinyxml.h.
Referenced by IsWhiteSpaceCondensed(), ReadText(), and SetCondenseWhiteSpace().
const char* OBT::TiXmlBase::errorString[TIXML_ERROR_STRING_COUNT] [static, protected] |
Definition at line 379 of file tiny/OBTtinyxml.h.
void* OBT::TiXmlBase::userData [protected] |