static int toColor (const char* value, int index) {
char digits[3];
char *error;
int color;
if (strlen(value) != 8) return -1;
value += index * 2;
digits[0] = *value;
digits[1] = *(value + 1);
digits[2] = '\0';
color = (int)strtoul(digits, &error, 16);
if (*error != 0) return -1;
return color;
}
cocos2d::Color4B stringToColor(std::string &str)
{
if (str.length() != 8)
{
return cocos2d::Color4B::WHITE;
}
const char *ch = str.c_str();
GLubyte r = (GLubyte)toColor(ch, 0);
GLubyte g = (GLubyte)toColor(ch, 1);
GLubyte b = (GLubyte)toColor(ch, 2);
GLubyte a = (GLubyte)toColor(ch, 3);
return cocos2d::Color4B(r, g, b, a);
}