version 1.42, 2007/07/30 06:50:57
|
version 1.42.4.1, 2008/09/17 18:31:54
|
|
|
return -1; | return -1; |
} | } |
| |
static inline int _getCharRef(char*& p, bool hex) |
static inline int _getCharRef(char*& p) |
{ | { |
char* end; | char* end; |
unsigned long ch; | unsigned long ch; |
|
Boolean hex = false; |
| |
if (hex) |
if (*p == 'x') |
{ | { |
ch = strtoul(p, &end, 16); |
hex = true; |
|
ch = strtoul(++p, &end, 16); |
} | } |
else | else |
{ | { |
|
|
return ch; | return ch; |
} | } |
| |
static void _normalize(Uint32& line, char*& p, char end_char, char*& start) |
// Parse an entity reference or a character reference |
|
static inline int _getRef(Uint32 line, char*& p) |
{ | { |
// Skip over leading whitespace: |
int ch; |
| |
_skipWhitespace(line, p); |
if (*p == '#') |
start = p; |
{ |
|
ch = _getCharRef(++p); |
|
} |
|
else |
|
{ |
|
ch = _getEntityRef(p); |
|
} |
| |
|
if (ch == -1) |
|
{ |
|
throw XmlException(XmlException::MALFORMED_REFERENCE, line); |
|
} |
|
|
|
return ch; |
|
} |
|
|
|
static inline void _normalizeElementValue( |
|
Uint32& line, |
|
char*& p) |
|
{ |
// Process one character at a time: | // Process one character at a time: |
| |
char* q = p; | char* q = p; |
| |
while (*p && (*p != end_char)) |
while (*p && (*p != '<')) |
{ | { |
if (_isspace(*p)) | if (_isspace(*p)) |
{ | { |
// Compress sequences of whitespace characters to a single space |
// Trim whitespace from the end of the value, but do not compress |
// character. Update line number when newlines encountered. |
// whitespace within the value. |
|
|
|
const char* start = p; |
| |
if (*p++ == '\n') | if (*p++ == '\n') |
{ | { |
line++; | line++; |
} | } |
| |
*q++ = ' '; |
|
|
|
_skipWhitespace(line, p); | _skipWhitespace(line, p); |
} |
|
else if (*p == '&') |
|
{ |
|
// Process entity characters and entity references: |
|
| |
p++; |
if (*p && (*p != '<')) |
int ch; |
|
|
|
if (*p == '#') |
|
{ | { |
*p++; |
// Transfer internal whitespace to q without compressing it. |
|
const char* i = start; |
if (*p == 'x') |
while (i < p) |
{ | { |
p++; |
*q++ = *i++; |
ch = _getCharRef(p, true); |
} |
} | } |
else | else |
{ | { |
ch = _getCharRef(p, false); |
// Do not transfer trailing whitespace to q. |
|
break; |
} | } |
} | } |
|
else if (*p == '&') |
|
{ |
|
// Process an entity reference or a character reference. |
|
|
|
*q++ = _getRef(line, ++p); |
|
} |
else | else |
{ | { |
ch = _getEntityRef(p); |
*q++ = *p++; |
|
} |
} | } |
| |
if (ch == -1) |
// If q got behind p, it is safe and necessary to null-terminate q |
|
|
|
if (q != p) |
{ | { |
throw XmlException(XmlException::MALFORMED_REFERENCE, line); |
*q = '\0'; |
} | } |
|
} |
|
|
|
static inline void _normalizeAttributeValue( |
|
Uint32& line, |
|
char*& p, |
|
char end_char, |
|
char*& start) |
|
{ |
|
// Skip over leading whitespace: |
| |
*q++ = ch; |
_skipWhitespace(line, p); |
|
start = p; |
|
|
|
// Process one character at a time: |
|
|
|
char* q = p; |
|
|
|
while (*p && (*p != end_char)) |
|
{ |
|
if (_isspace(*p)) |
|
{ |
|
// Compress sequences of whitespace characters to a single space |
|
// character. Update line number when newlines encountered. |
|
|
|
if (*p++ == '\n') |
|
{ |
|
line++; |
|
} |
|
|
|
*q++ = ' '; |
|
|
|
_skipWhitespace(line, p); |
|
} |
|
else if (*p == '&') |
|
{ |
|
// Process an entity reference or a character reference. |
|
|
|
*q++ = _getRef(line, ++p); |
} | } |
else | else |
{ | { |
|
|
} | } |
} | } |
| |
// We encountered a the end_char or a zero-terminator. |
|
|
|
*q = *p; |
|
|
|
// Remove single trailing whitespace (consecutive whitespaces already | // Remove single trailing whitespace (consecutive whitespaces already |
// compressed above). Since p >= q, we can tell if we need to strip a | // compressed above). Since p >= q, we can tell if we need to strip a |
// trailing space from q by looking at the end of p. We must not look at | // trailing space from q by looking at the end of p. We must not look at |
// the last character of p, though, if p is an empty string. | // the last character of p, though, if p is an empty string. |
|
Boolean adjust_q = (p != start) && _isspace(p[-1]); |
| |
if ((p != start) && _isspace(p[-1])) |
// We encountered a the end_char or a zero-terminator. |
|
|
|
*q = *p; |
|
|
|
if (adjust_q) |
{ | { |
q--; | q--; |
} | } |
|
|
{ | { |
// Normalize the content: | // Normalize the content: |
| |
char* start; |
char* start = _current; |
_normalize(_line, _current, '<', start); |
_normalizeElementValue(_line, _current); |
| |
// Get the content: | // Get the content: |
| |
|
|
char quote = *p++; | char quote = *p++; |
| |
char* start; | char* start; |
_normalize(_line, p, quote, start); |
_normalizeAttributeValue(_line, p, quote, start); |
attr.value = start; | attr.value = start; |
| |
if (*p != quote) | if (*p != quote) |