version 1.33, 2005/10/31 17:39:12
|
version 1.34, 2005/11/03 00:35:04
|
|
|
#include "XmlParser.h" | #include "XmlParser.h" |
#include "Logger.h" | #include "Logger.h" |
#include "ExceptionRep.h" | #include "ExceptionRep.h" |
|
#include "CharSet.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
// Section 2.3 of XML 1.0 Standard (http://www.w3.org/TR/REC-xml) | // Section 2.3 of XML 1.0 Standard (http://www.w3.org/TR/REC-xml) |
// defines white space as: | // defines white space as: |
// S ::= (#x20 | #x9 | #xD | #xA)+ | // S ::= (#x20 | #x9 | #xD | #xA)+ |
static int _isspace(char c) |
static inline int _isspace(char c) |
{ | { |
if (c == ' ' || c == '\r' || c == '\t' || c == '\n') |
return CharSet::isSpace((Uint8)c); |
return 1; |
|
return 0; |
|
} | } |
| |
|
|
static Uint32 _REFERENCES_SIZE = (sizeof(_references) / sizeof(_references[0])); | static Uint32 _REFERENCES_SIZE = (sizeof(_references) / sizeof(_references[0])); |
| |
// Remove all redundant spaces from the given string: | // Remove all redundant spaces from the given string: |
|
|
| |
} | } |
| |
|
inline void _skipWhitespace(Uint32& line, char*& p) |
|
{ |
|
while (*p && _isspace(*p)) |
|
{ |
|
if (*p == '\n') |
|
line++; |
|
|
|
p++; |
|
} |
|
} |
|
|
Boolean XmlParser::next(XmlEntry& entry) | Boolean XmlParser::next(XmlEntry& entry) |
{ | { |
if (!_putBackStack.isEmpty()) | if (!_putBackStack.isEmpty()) |
|
|
| |
// Skip over any whitespace: | // Skip over any whitespace: |
| |
_skipWhitespace(_current); |
_skipWhitespace(_line, _current); |
| |
if (!*_current) | if (!*_current) |
{ | { |
|
|
// Nothing to do! | // Nothing to do! |
} | } |
| |
void XmlParser::_skipWhitespace(char*& p) |
|
{ |
|
while (*p && _isspace(*p)) |
|
{ |
|
if (*p == '\n') |
|
_line++; |
|
|
|
p++; |
|
} |
|
} |
|
|
|
Boolean XmlParser::_getElementName(char*& p) | Boolean XmlParser::_getElementName(char*& p) |
{ | { |
if (!(((*p >= 'A') && (*p <= 'Z')) || | if (!(((*p >= 'A') && (*p <= 'Z')) || |
|
|
if (_isspace(*p)) | if (_isspace(*p)) |
{ | { |
*p++ = '\0'; | *p++ = '\0'; |
_skipWhitespace(p); |
_skipWhitespace(_line, p); |
} | } |
| |
if (*p == '>') | if (*p == '>') |
|
|
if (_isspace(*p)) | if (_isspace(*p)) |
{ | { |
*p++ = '\0'; | *p++ = '\0'; |
_skipWhitespace(p); |
_skipWhitespace(_line, p); |
} | } |
| |
if (*p == '>') | if (*p == '>') |
|
|
| |
char* term = p; | char* term = p; |
| |
_skipWhitespace(p); |
_skipWhitespace(_line, p); |
| |
if (*p != '=') | if (*p != '=') |
throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); |
| |
p++; | p++; |
| |
_skipWhitespace(p); |
_skipWhitespace(_line, p); |
| |
*term = '\0'; | *term = '\0'; |
} | } |
|
|
throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} | } |
| |
_skipWhitespace(p); |
_skipWhitespace(_line, p); |
| |
if (entry.attributeCount == XmlEntry::MAX_ATTRIBUTES) | if (entry.attributeCount == XmlEntry::MAX_ATTRIBUTES) |
throw XmlException(XmlException::TOO_MANY_ATTRIBUTES, _line); | throw XmlException(XmlException::TOO_MANY_ATTRIBUTES, _line); |