MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / parseColorCString

Function parseColorCString

src/common/ParseColor.cpp:159–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157//============================================================================//
158
159bool 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
196bool parseColorString(const std::string& str, fvec4& color) {

Callers 1

parseColorStringFunction · 0.85

Calls 4

skipWhitespaceFunction · 0.85
parseHexFormatFunction · 0.85
parseFloatFormatFunction · 0.85
parseNamedFormatFunction · 0.85

Tested by

no test coverage detected