version 1.18.6.1, 2003/07/29 15:08:29
|
version 1.28, 2004/05/01 16:52:23
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2003//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development |
// The Open Group, Tivoli Systems |
// Company, L. P., IBM Corp., The Open Group, Tivoli Systems. |
|
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; |
|
// IBM Corp.; EMC Corporation, The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
{ "'", 6, '\'' } | { "'", 6, '\'' } |
}; | }; |
| |
|
|
|
// Implements a check for a whitespace character, without calling |
|
// isspace( ). The isspace( ) function is locale-sensitive, |
|
// and incorrectly flags some chars above 0x7f as whitespace. This |
|
// causes the XmlParser to incorrectly parse UTF-8 data. |
|
// |
|
// Section 2.3 of XML 1.0 Standard (http://www.w3.org/TR/REC-xml) |
|
// defines white space as: |
|
// S ::= (#x20 | #x9 | #xD | #xA)+ |
|
static int _isspace(char c) |
|
{ |
|
if (c == ' ' || c == '\r' || c == '\t' || c == '\n') |
|
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: |
|
|
| |
// Remove leading spaces: | // Remove leading spaces: |
| |
while (isspace(*p)) |
while (_isspace(*p)) |
p++; | p++; |
| |
if (p != text) | if (p != text) |
|
|
{ | { |
// Advance to the next space: | // Advance to the next space: |
| |
while (*p && !isspace(*p)) |
while (*p && !_isspace(*p)) |
p++; | p++; |
| |
if (!*p) | if (!*p) |
|
|
| |
char* q = p++; | char* q = p++; |
| |
while (isspace(*p)) |
while (_isspace(*p)) |
p++; | p++; |
| |
// Discard trailing spaces (if we are at the end): | // Discard trailing spaces (if we are at the end): |
|
|
"Common.XmlParser.SEMANTIC_ERROR" | "Common.XmlParser.SEMANTIC_ERROR" |
}; | }; |
| |
// l10n TODO replace _formMessage with the commented one and uncomment |
// l10n replace _formMessage (comment out the old one) |
// the new constructors |
|
/* | /* |
static String _formMessage(Uint32 code, Uint32 line, const String& message) | static String _formMessage(Uint32 code, Uint32 line, const String& message) |
{ | { |
|
|
MessageLoaderParms& msgParms) | MessageLoaderParms& msgParms) |
: Exception(_formPartialMessage(code, lineNumber)) | : Exception(_formPartialMessage(code, lineNumber)) |
{ | { |
|
if (msgParms.default_msg.size()) |
|
{ |
|
msgParms.default_msg = ": " + msgParms.default_msg; |
|
} |
_rep->message.append(MessageLoader::getMessage(msgParms)); | _rep->message.append(MessageLoader::getMessage(msgParms)); |
} | } |
| |
|
|
| |
void XmlParser::_skipWhitespace(char*& p) | void XmlParser::_skipWhitespace(char*& p) |
{ | { |
while (*p && isspace(*p)) |
while (*p && _isspace(*p)) |
{ | { |
if (*p == '\n') | if (*p == '\n') |
_line++; | _line++; |
|
|
| |
Boolean XmlParser::_getElementName(char*& p) | Boolean XmlParser::_getElementName(char*& p) |
{ | { |
if (!isalpha(*p) && *p != '_') |
if (!(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
throw XmlException(XmlException::BAD_START_TAG, _line); | throw XmlException(XmlException::BAD_START_TAG, _line); |
|
p++; |
| |
while (*p && |
while ((*p) && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
((*p >= '0') && (*p <= '9')) || |
|
*p == '_' || *p == '-' || *p == ':' || *p == '.')) |
p++; | p++; |
| |
// The next character must be a space: | // The next character must be a space: |
| |
if (isspace(*p)) |
if (_isspace(*p)) |
{ | { |
*p++ = '\0'; | *p++ = '\0'; |
_skipWhitespace(p); | _skipWhitespace(p); |
|
|
{ | { |
openCloseElement = false; | openCloseElement = false; |
| |
if (!isalpha(*p) && *p != '_') |
if (!(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
throw XmlException(XmlException::BAD_START_TAG, _line); | throw XmlException(XmlException::BAD_START_TAG, _line); |
|
p++; |
| |
while (*p && |
while ((*p) && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
((*p >= '0') && (*p <= '9')) || |
|
*p == '_' || *p == '-' || *p == ':' || *p == '.')) |
p++; | p++; |
| |
// The next character must be a space: | // The next character must be a space: |
| |
if (isspace(*p)) |
if (_isspace(*p)) |
{ | { |
*p++ = '\0'; | *p++ = '\0'; |
_skipWhitespace(p); | _skipWhitespace(p); |
|
|
| |
void XmlParser::_getAttributeNameAndEqual(char*& p) | void XmlParser::_getAttributeNameAndEqual(char*& p) |
{ | { |
if (!isalpha(*p) && *p != '_') |
if (!(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); | throw XmlException(XmlException::BAD_ATTRIBUTE_NAME, _line); |
|
p++; |
| |
while (*p && |
while ((*p) && |
(isalnum(*p) || *p == '_' || *p == '-' || *p == ':' || *p == '.')) |
(((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
((*p >= '0') && (*p <= '9')) || |
|
*p == '_' || *p == '-' || *p == ':' || *p == '.')) |
p++; | p++; |
| |
char* term = p; | char* term = p; |
|
|
| |
return; | return; |
} | } |
else if (isalpha(*p) || *p == '_') |
else if ((((*p >= 'A') && (*p <= 'Z')) || |
|
((*p >= 'a') && (*p <= 'z')) || |
|
(*p == '_'))) |
{ | { |
entry.type = XmlEntry::START_TAG; | entry.type = XmlEntry::START_TAG; |
entry.text = p; | entry.text = p; |
|
|
{ | { |
// The next thing must a space or a "?>": | // The next thing must a space or a "?>": |
| |
if (!(p[0] == '?' && p[1] == '>') && !isspace(*p)) |
if (!(p[0] == '?' && p[1] == '>') && !_isspace(*p)) |
{ | { |
throw XmlException( | throw XmlException( |
XmlException::BAD_ATTRIBUTE_VALUE, _line); | XmlException::BAD_ATTRIBUTE_VALUE, _line); |
} | } |
} | } |
else if (!(*p == '>' || (p[0] == '/' && p[1] == '>') || isspace(*p))) |
else if (!(*p == '>' || (p[0] == '/' && p[1] == '>') || _isspace(*p))) |
{ | { |
// The next thing must be a space or a '>': | // The next thing must be a space or a '>': |
| |
|
|
{ | { |
first = str; | first = str; |
| |
while (isspace(*first)) |
while (_isspace(*first)) |
first++; | first++; |
| |
if (!*first) | if (!*first) |
|
|
| |
last = first + strlen(first); | last = first + strlen(first); |
| |
while (last != first && isspace(last[-1])) |
while (last != first && _isspace(last[-1])) |
last--; | last--; |
} | } |
| |
|
|
if (!getAttributeValue(name, tmp)) | if (!getAttributeValue(name, tmp)) |
return false; | return false; |
| |
value = tmp; |
value = String(tmp); |
return true; | return true; |
} | } |
| |