From 36cd5caf956c087995a62983ad09c15250f29475 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 15 Oct 2010 12:19:13 +0000 Subject: COMMON: Add XMLParser::parseIntegerKey variant accepting a Common::String Almost all places where we used XMLParser::parseIntegerKey were using it like this: XMLParser::parseIntegerKey(str.c_str(), ...) Since this makes the code harder to read, I overloaded the method to also accept Commmon::String directly. Also removed all .c_str() invocations where necessary. svn-id: r53479 --- common/xmlparser.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'common/xmlparser.cpp') diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 1c652fa19d..48f4f7bdf4 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -229,6 +229,47 @@ bool XMLParser::parseKeyValue(Common::String keyName) { return true; } +bool XMLParser::parseIntegerKey(const char *key, int count, ...) { + bool result; + va_list args; + va_start(args, count); + result = vparseIntegerKey(key, count, args); + va_end(args); + return result; +} + +bool XMLParser::parseIntegerKey(const Common::String &key, int count, ...) { + bool result; + va_list args; + va_start(args, count); + result = vparseIntegerKey(key.c_str(), count, args); + va_end(args); + return result; +} + +bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { + char *parseEnd; + int *num_ptr; + + while (count--) { + while (isspace(*key)) + key++; + + num_ptr = va_arg(args, int*); + *num_ptr = strtol(key, &parseEnd, 10); + + key = parseEnd; + + while (isspace(*key)) + key++; + + if (count && *key++ != ',') + return false; + } + + return (*key == 0); +} + bool XMLParser::closeKey() { bool ignore = false; bool result = true; -- cgit v1.2.3 From 2fed5ff83244d6d66199239c3753e5934ed18b7b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 15 Oct 2010 12:19:34 +0000 Subject: COMMON: Move XMLParser method impls to .cpp file; make skipComments non-virtual svn-id: r53480 --- common/xmlparser.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'common/xmlparser.cpp') diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 48f4f7bdf4..ab56ba3751 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -451,5 +451,61 @@ bool XMLParser::parse() { return true; } +bool XMLParser::skipSpaces() { + if (!isspace(_char)) + return false; + + while (_char && isspace(_char)) + _char = _stream->readByte(); + + return true; +} + +bool XMLParser::skipComments() { + if (_char == '<') { + _char = _stream->readByte(); + + if (_char != '!') { + _stream->seek(-1, SEEK_CUR); + _char = '<'; + return false; + } + + if (_stream->readByte() != '-' || _stream->readByte() != '-') + return parserError("Malformed comment syntax."); + + _char = _stream->readByte(); + + while (_char) { + if (_char == '-') { + if (_stream->readByte() == '-') { + + if (_stream->readByte() != '>') + return parserError("Malformed comment (double-hyphen inside comment body)."); + + _char = _stream->readByte(); + return true; + } + } + + _char = _stream->readByte(); + } + + return parserError("Comment has no closure."); + } + + return false; +} + +bool XMLParser::parseToken() { + _token.clear(); + + while (isValidNameChar(_char)) { + _token += _char; + _char = _stream->readByte(); + } + + return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/'; } +} // End of namespace Common -- cgit v1.2.3