[Scummvm-cvs-logs] SF.net SVN: scummvm:[53479] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Oct 15 14:19:13 CEST 2010


Revision: 53479
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53479&view=rev
Author:   fingolfin
Date:     2010-10-15 12:19:13 +0000 (Fri, 15 Oct 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
    scummvm/trunk/common/xmlparser.cpp
    scummvm/trunk/common/xmlparser.h
    scummvm/trunk/engines/sword25/gfx/animationresource.cpp
    scummvm/trunk/engines/sword25/gfx/fontresource.cpp
    scummvm/trunk/gui/ThemeParser.cpp

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2010-10-15 12:18:41 UTC (rev 53478)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2010-10-15 12:19:13 UTC (rev 53479)
@@ -270,7 +270,7 @@
 
 	int r, g, b;
 	if (node->values.contains("transparent_color")) {
-		if (!parseIntegerKey(node->values["transparent_color"].c_str(), 3, &r, &g, &b))
+		if (!parseIntegerKey(node->values["transparent_color"], 3, &r, &g, &b))
 			return parserError("Could not parse color value");
 	} else {
 		// default to purple
@@ -281,7 +281,7 @@
 	_mode->transparentColor = format.RGBToColor(r, g, b);
 
 	if (node->values.contains("display_font_color")) {
-		if (!parseIntegerKey(node->values["display_font_color"].c_str(), 3, &r, &g, &b))
+		if (!parseIntegerKey(node->values["display_font_color"], 3, &r, &g, &b))
 			return parserError("Could not parse color value");
 	} else {
 		r = g = b = 0; // default to black
@@ -336,7 +336,7 @@
 
 bool VirtualKeyboardParser::parseRect(Rect &rect, const String& coords) {
 	int x1, y1, x2, y2;
-	if (!parseIntegerKey(coords.c_str(), 4, &x1, &y1, &x2, &y2))
+	if (!parseIntegerKey(coords, 4, &x1, &y1, &x2, &y2))
 		return parserError("Invalid coords for rect area");
 	rect.left = x1;
 	rect.top = y1;

Modified: scummvm/trunk/common/xmlparser.cpp
===================================================================
--- scummvm/trunk/common/xmlparser.cpp	2010-10-15 12:18:41 UTC (rev 53478)
+++ scummvm/trunk/common/xmlparser.cpp	2010-10-15 12:19:13 UTC (rev 53479)
@@ -229,6 +229,47 @@
 	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;

Modified: scummvm/trunk/common/xmlparser.h
===================================================================
--- scummvm/trunk/common/xmlparser.h	2010-10-15 12:18:41 UTC (rev 53478)
+++ scummvm/trunk/common/xmlparser.h	2010-10-15 12:19:13 UTC (rev 53479)
@@ -395,33 +395,10 @@
 	 *            by reference.
 	 * @returns True if the parsing succeeded.
 	 */
-	bool parseIntegerKey(const char *key, int count, ...) {
-		char *parseEnd;
-		int *num_ptr;
+	bool parseIntegerKey(const char *key, int count, ...);
+	bool parseIntegerKey(const Common::String &keyStr, int count, ...);
+	bool vparseIntegerKey(const char *key, int count, va_list args);
 
-		va_list args;
-		va_start(args, count);
-
-		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;
-		}
-
-		va_end(args);
-		return (*key == 0);
-	}
-
 	bool parseXMLHeader(ParserNode *node);
 
 	/**

Modified: scummvm/trunk/engines/sword25/gfx/animationresource.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/animationresource.cpp	2010-10-15 12:18:41 UTC (rev 53478)
+++ scummvm/trunk/engines/sword25/gfx/animationresource.cpp	2010-10-15 12:19:13 UTC (rev 53479)
@@ -116,7 +116,7 @@
 }
 
 bool AnimationResource::parserCallback_animation(ParserNode *node) {
-	if (!parseIntegerKey(node->values["fps"].c_str(), 1, &_FPS) || (_FPS < MIN_FPS) || (_FPS > MAX_FPS)) {
+	if (!parseIntegerKey(node->values["fps"], 1, &_FPS) || (_FPS < MIN_FPS) || (_FPS > MAX_FPS)) {
 		return parserError("Illegal or missing fps attribute in <animation> tag in \"%s\". Assuming default (\"%d\").",
 		                 getFileName().c_str(), DEFAULT_FPS);
 	}

Modified: scummvm/trunk/engines/sword25/gfx/fontresource.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/fontresource.cpp	2010-10-15 12:18:41 UTC (rev 53478)
+++ scummvm/trunk/engines/sword25/gfx/fontresource.cpp	2010-10-15 12:19:13 UTC (rev 53479)
@@ -93,13 +93,13 @@
 	// Get the attributes of the font
 	Common::String bitmapFilename = node->values["bitmap"];
 
-	if (!parseIntegerKey(node->values["lineheight"].c_str(), 1, &_LineHeight)) {
+	if (!parseIntegerKey(node->values["lineheight"], 1, &_LineHeight)) {
 		BS_LOG_WARNINGLN("Illegal or missing lineheight attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
 		                 getFileName().c_str(), DEFAULT_LINEHEIGHT);
 		_LineHeight = DEFAULT_LINEHEIGHT;
 	}
 
-	if (!parseIntegerKey(node->values["gap"].c_str(), 1, &_GapWidth)) {
+	if (!parseIntegerKey(node->values["gap"], 1, &_GapWidth)) {
 		BS_LOG_WARNINGLN("Illegal or missing gap attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
 		                 getFileName().c_str(), DEFAULT_GAPWIDTH);
 		_GapWidth = DEFAULT_GAPWIDTH;
@@ -131,20 +131,20 @@
 	// Get the attributes of the character
 	int charCode, top, left, right, bottom;
 
-	if (!parseIntegerKey(node->values["code"].c_str(), 1, &charCode) || (charCode < 0) || (charCode >= 256)) {
+	if (!parseIntegerKey(node->values["code"], 1, &charCode) || (charCode < 0) || (charCode >= 256)) {
 		return parserError("Illegal or missing code attribute in <character> tag in \"%s\".", getFileName().c_str());
 	}
 
-	if (!parseIntegerKey(node->values["top"].c_str(), 1, &top) || (top < 0)) {
+	if (!parseIntegerKey(node->values["top"], 1, &top) || (top < 0)) {
 		return parserError("Illegal or missing top attribute in <character> tag in \"%s\".", getFileName().c_str());
 	}
-	if (!parseIntegerKey(node->values["left"].c_str(), 1, &left) || (left < 0)) {
+	if (!parseIntegerKey(node->values["left"], 1, &left) || (left < 0)) {
 		return parserError("Illegal or missing left attribute in <character> tag in \"%s\".", getFileName().c_str());
 	}
-	if (!parseIntegerKey(node->values["right"].c_str(), 1, &right) || (right < 0)) {
+	if (!parseIntegerKey(node->values["right"], 1, &right) || (right < 0)) {
 		return parserError("Illegal or missing right attribute in <character> tag in \"%s\".", getFileName().c_str());
 	}
-	if (!parseIntegerKey(node->values["bottom"].c_str(), 1, &bottom) || (bottom < 0)) {
+	if (!parseIntegerKey(node->values["bottom"], 1, &bottom) || (bottom < 0)) {
 		return parserError("Illegal or missing bottom attribute in <character> tag in \"%s\".", getFileName().c_str());
 	}
 

Modified: scummvm/trunk/gui/ThemeParser.cpp
===================================================================
--- scummvm/trunk/gui/ThemeParser.cpp	2010-10-15 12:18:41 UTC (rev 53478)
+++ scummvm/trunk/gui/ThemeParser.cpp	2010-10-15 12:19:13 UTC (rev 53479)
@@ -195,7 +195,7 @@
 
 	if (_palette.contains(node->values["color"]))
 		getPaletteColor(node->values["color"], red, green, blue);
-	else if (!parseIntegerKey(node->values["color"].c_str(), 3, &red, &green, &blue))
+	else if (!parseIntegerKey(node->values["color"], 3, &red, &green, &blue))
 		return parserError("Error parsing color value for text color definition.");
 
 	if (!_theme->addTextColor(colorId, red, green, blue))
@@ -216,10 +216,10 @@
 
 	int spotx, spoty, scale;
 
-	if (!parseIntegerKey(node->values["hotspot"].c_str(), 2, &spotx, &spoty))
+	if (!parseIntegerKey(node->values["hotspot"], 2, &spotx, &spoty))
 		return parserError("Error parsing cursor Hot Spot coordinates.");
 
-	if (!parseIntegerKey(node->values["scale"].c_str(), 1, &scale))
+	if (!parseIntegerKey(node->values["scale"], 1, &scale))
 		return parserError("Error parsing cursor scale.");
 
 	if (!_theme->createCursor(node->values["file"], spotx, spoty, scale))
@@ -286,7 +286,7 @@
 
 	int red, green, blue;
 
-	if (parseIntegerKey(node->values["rgb"].c_str(), 3, &red, &green, &blue) == false ||
+	if (parseIntegerKey(node->values["rgb"], 3, &red, &green, &blue) == false ||
 		red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255)
 		return parserError("Error parsing RGB values for palette color '%s'", name.c_str());\
 
@@ -387,7 +387,7 @@
  */
 #define __PARSER_ASSIGN_INT(struct_name, key_name, force) \
 	if (stepNode->values.contains(key_name)) { \
-		if (!parseIntegerKey(stepNode->values[key_name].c_str(), 1, &x)) \
+		if (!parseIntegerKey(stepNode->values[key_name], 1, &x)) \
 			return parserError("Error parsing key value for '%s'.", key_name); \
 		\
 		drawstep->struct_name = x; \
@@ -411,7 +411,7 @@
 			red = _palette[val].r; \
 			green = _palette[val].g; \
 			blue = _palette[val].b; \
-		} else if (parseIntegerKey(val.c_str(), 3, &red, &green, &blue) == false || \
+		} else if (parseIntegerKey(val, 3, &red, &green, &blue) == false || \
 			red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) \
 			return parserError("Error parsing color struct '%s'", val.c_str());\
 		\
@@ -481,7 +481,7 @@
 			drawstep->autoWidth = false;
 
 			val = stepNode->values["width"];
-			if (parseIntegerKey(val.c_str(), 1, &x))
+			if (parseIntegerKey(val, 1, &x))
 				drawstep->w = x;
 			else if (val == "height")
 				drawstep->w = -1;
@@ -490,7 +490,7 @@
 			if (stepNode->values.contains("xpos")) {
 				val = stepNode->values["xpos"];
 
-				if (parseIntegerKey(val.c_str(), 1, &x))
+				if (parseIntegerKey(val, 1, &x))
 					drawstep->x = x;
 				else if (val == "center")
 					drawstep->xAlign = Graphics::DrawStep::kVectorAlignCenter;
@@ -509,7 +509,7 @@
 			drawstep->autoHeight = false;
 
 			val = stepNode->values["height"];
-			if (parseIntegerKey(val.c_str(), 1, &x))
+			if (parseIntegerKey(val, 1, &x))
 				drawstep->h = x;
 			else if (val == "width")
 				drawstep->h = -1;
@@ -518,7 +518,7 @@
 			if (stepNode->values.contains("ypos")) {
 				val = stepNode->values["ypos"];
 
-				if (parseIntegerKey(val.c_str(), 1, &x))
+				if (parseIntegerKey(val, 1, &x))
 					drawstep->y = x;
 				else if (val == "center")
 					drawstep->yAlign = Graphics::DrawStep::kVectorAlignCenter;
@@ -569,7 +569,7 @@
 	if (_theme->getEvaluator()->hasVar(node->values["value"]) == true)
 		value = _theme->getEvaluator()->getVar(node->values["value"]);
 
-	else if (!parseIntegerKey(node->values["value"].c_str(), 1, &value))
+	else if (!parseIntegerKey(node->values["value"], 1, &value))
 		return parserError("Invalid definition for '%s'.", var.c_str());
 
 	_theme->getEvaluator()->setVar(var, value);
@@ -608,7 +608,7 @@
 			if (_theme->getEvaluator()->hasVar(node->values["width"]) == true)
 				width = _theme->getEvaluator()->getVar(node->values["width"]);
 
-			else if (!parseIntegerKey(node->values["width"].c_str(), 1, &width))
+			else if (!parseIntegerKey(node->values["width"], 1, &width))
 				return parserError("Corrupted width value in key for %s", var.c_str());
 		}
 
@@ -616,7 +616,7 @@
 			if (_theme->getEvaluator()->hasVar(node->values["height"]) == true)
 				height = _theme->getEvaluator()->getVar(node->values["height"]);
 
-			else if (!parseIntegerKey(node->values["height"].c_str(), 1, &height))
+			else if (!parseIntegerKey(node->values["height"], 1, &height))
 				return parserError("Corrupted height value in key for %s", var.c_str());
 		}
 
@@ -651,7 +651,7 @@
 	}
 
 	if (node->values.contains("inset")) {
-		if (!parseIntegerKey(node->values["inset"].c_str(), 1, &inset))
+		if (!parseIntegerKey(node->values["inset"], 1, &inset))
 			return false;
 	}
 
@@ -682,7 +682,7 @@
 	int spacing = -1;
 
 	if (node->values.contains("spacing")) {
-		if (!parseIntegerKey(node->values["spacing"].c_str(), 1, &spacing))
+		if (!parseIntegerKey(node->values["spacing"], 1, &spacing))
 			return false;
 	}
 
@@ -697,7 +697,7 @@
 	if (node->values.contains("padding")) {
 		int paddingL, paddingR, paddingT, paddingB;
 
-		if (!parseIntegerKey(node->values["padding"].c_str(), 4, &paddingL, &paddingR, &paddingT, &paddingB))
+		if (!parseIntegerKey(node->values["padding"], 4, &paddingL, &paddingR, &paddingT, &paddingB))
 			return false;
 
 		_theme->getEvaluator()->addPadding(paddingL, paddingR, paddingT, paddingB);
@@ -713,7 +713,7 @@
 		if (_theme->getEvaluator()->hasVar(node->values["size"]))
 			size = _theme->getEvaluator()->getVar(node->values["size"]);
 
-		else if (!parseIntegerKey(node->values["size"].c_str(), 1, &size))
+		else if (!parseIntegerKey(node->values["size"], 1, &size))
 			return parserError("Invalid value for Spacing size.");
 	}
 
@@ -734,7 +734,7 @@
 	if (node->values.contains("size")) {
 		int width, height;
 
-		if (!parseIntegerKey(node->values["size"].c_str(), 2, &width, &height)) {
+		if (!parseIntegerKey(node->values["size"], 2, &width, &height)) {
 			Common::StringTokenizer tokenizer(node->values["size"], " ,");
 			Common::String wtoken, htoken;
 			char *parseEnd;
@@ -779,7 +779,7 @@
 	if (node->values.contains("pos")) {
 		int x, y;
 
-		if (!parseIntegerKey(node->values["pos"].c_str(), 2, &x, &y)) {
+		if (!parseIntegerKey(node->values["pos"], 2, &x, &y)) {
 			Common::StringTokenizer tokenizer(node->values["pos"], " ,");
 			Common::String xpos, ypos;
 			char *parseEnd;
@@ -835,7 +835,7 @@
 	if (node->values.contains("padding")) {
 		int paddingL, paddingR, paddingT, paddingB;
 
-		if (!parseIntegerKey(node->values["padding"].c_str(), 4, &paddingL, &paddingR, &paddingT, &paddingB))
+		if (!parseIntegerKey(node->values["padding"], 4, &paddingL, &paddingR, &paddingT, &paddingB))
 			return false;
 
 		_theme->getEvaluator()->setVar(var + "Padding.Left", paddingL);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list