| 157 | //============================================================================// |
| 158 | |
| 159 | bool parseColorCString(const char* str, fvec4& color) { |
| 160 | static const float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; |
| 161 | |
| 162 | // default to opaque white |
| 163 | memcpy(color, white, sizeof(float[4])); |
| 164 | |
| 165 | // strip leading space |
| 166 | str = TextUtils::skipWhitespace(str); |
| 167 | |
| 168 | // no string |
| 169 | if (str[0] == 0) { |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | // hexadecimal format (#rgb, #rgba, #rrggbb, or #rrggbbaa) |
| 174 | if (str[0] == '#') { |
| 175 | return parseHexFormat(str + 1, color); |
| 176 | } |
| 177 | |
| 178 | // hexadecimal format (0xRGB, 0xRGBA, 0xRRGGBB, or 0xRRGGBBAA) |
| 179 | if ((str[0] == '0') && (str[1] == 'x')) { |
| 180 | return parseHexFormat(str + 2, color); |
| 181 | } |
| 182 | |
| 183 | // float format (either 3 or 4 floating point values) |
| 184 | if (((str[0] >= '0') && (str[0] <= '9')) |
| 185 | || (str[0] == '.') |
| 186 | || (str[0] == '+') |
| 187 | || (str[0] == '-')) { |
| 188 | return parseFloatFormat(str, color); |
| 189 | } |
| 190 | |
| 191 | // named string format ("red 0.2" format is accepted for alpha values) |
| 192 | return parseNamedFormat(str, color); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | bool parseColorString(const std::string& str, fvec4& color) { |
no test coverage detected