diff options
| -rw-r--r-- | gui/ThemeParser.cpp | 43 | ||||
| -rw-r--r-- | gui/ThemeParser.h | 25 | 
2 files changed, 35 insertions, 33 deletions
| diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index c75340ada2..fc960ca4d7 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -100,8 +100,7 @@ void ThemeParser::parseKeyValue(Common::String &key_name) {  		return;  	} -	while (isspace(_text[_pos])) -		_pos++; +	skipSpaces();  	Common::String data; @@ -131,18 +130,8 @@ bool ThemeParser::parse() {  		if (_state == kParserError)  			break; -		while (isspace(_text[_pos])) -			_pos++; - -		// comment handling: skip everything between /* and */ -		if (_text[_pos] == '/' && _text[_pos + 1] == '*') { -			_pos += 2; -			while (_text[_pos++]) { -				if (_text[_pos - 2] == '*' && _text[_pos - 1] == '/') -					break; -			} -			continue; -		} +		skipSpaces(); +		skipComments();  		switch (_state) {  			case kParserNeedKey: @@ -157,25 +146,26 @@ bool ThemeParser::parse() {  					while (isValidNameChar(_text[_pos]))  						_token += _text[_pos++]; -					if (!_activeKey.empty() && _token == _activeKey.top()) { +					if (_activeKey.empty() || _token != _activeKey.top()) +						parserError("Unexpected closure."); +					else {  						_activeKey.pop();  						_keyValues.pop(); -						while (isspace(_text[_pos]) || _text[_pos] == '>') -							_pos++; +						skipSpaces(); -						break; -					} else { -						parserError("Unexpected closure."); -						break; +						if (_text[_pos++] != '>') +							parserError("Malformed tag closure.");  					} +	 +					break;  				}  				_keyValues.push(Common::StringMap()); -				_state = kParserKeyNeedName; +				_state = kParserNeedKeyName;  				break; -			case kParserKeyNeedName: +			case kParserNeedKeyName:  				_token.clear();  				while (isValidNameChar(_text[_pos]))  					_token += _text[_pos++]; @@ -185,11 +175,11 @@ bool ThemeParser::parse() {  					break;  				} -				_state = kParserKeyNeedToken; +				_state = kParserNeedKeyValues;  				_activeKey.push(_token);  				break; -			case kParserKeyNeedToken: +			case kParserNeedKeyValues:  				_token.clear();  				if ((_text[_pos] == '/' && _text[_pos + 1] == '>') || _text[_pos] == '>') { @@ -203,8 +193,7 @@ bool ThemeParser::parse() {  				while (isValidNameChar(_text[_pos]))  					_token += _text[_pos++]; -				while (isspace(_text[_pos])) -					_pos++; +				skipSpaces();  				if (_text[_pos] != '=') {  					parserError("Unexpected character after key name."); diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h index 22ad50a333..f87708e3f2 100644 --- a/gui/ThemeParser.h +++ b/gui/ThemeParser.h @@ -50,13 +50,10 @@ public:  	~ThemeParser() {}  	enum ParserState { -		kParserKeyNeedName, -		kParserKeyNeedToken, -		kParserKeyNeedSubkey,  		kParserNeedKey, -		kParserInComment, -		kParserError, -		kParserSuccess +		kParserNeedKeyName, +		kParserNeedKeyValues, +		kParserError  	};  	bool parse(); @@ -71,6 +68,22 @@ protected:  	void parserCallback_DRAW();  	void parserCallback_DRAWDATA(); +	inline void skipSpaces() { +		while (isspace(_text[_pos])) +			_pos++; +	} + +	inline void skipComments() { +		if (_text[_pos] == '/' && _text[_pos + 1] == '*') { +			_pos += 2; +			while (_text[_pos++]) { +				if (_text[_pos - 2] == '*' && _text[_pos - 1] == '/') +					break; +			} +			skipSpaces(); +		} +	} +  	int _pos;  	char *_text; | 
