MCPcopy Create free account
hub / github.com/Tencent/tgfx / parseHexColorToken

Method parseHexColorToken

src/svg/SVGAttributeParser.cpp:270–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268}
269
270bool SVGAttributeParser::parseHexColorToken(Color* c) {
271 RestoreCurPos restoreCurPos(this);
272
273 const char* hexEnd;
274 if (!this->parseExpectedStringToken("#") || !this->matchHexToken(&hexEnd)) {
275 return false;
276 }
277
278 uint32_t v;
279 std::string hexString(currentPos, static_cast<uint32_t>(hexEnd - currentPos));
280 SVGParse::FindHex(hexString.c_str(), &v);
281
282 switch (hexString.size()) {
283 case 6:
284 // matched #xxxxxxx
285 break;
286 case 3:
287 // matched '#xxx;
288 v = ((v << 12) & 0x00f00000) | ((v << 8) & 0x000ff000) | ((v << 4) & 0x00000ff0) |
289 ((v << 0) & 0x0000000f);
290 break;
291 default:
292 return false;
293 }
294
295 *c = Uint32ToColor(v | 0xff000000);
296 currentPos = hexEnd;
297
298 restoreCurPos.clear();
299 return true;
300}
301
302bool SVGAttributeParser::parseColorComponentIntegralToken(int32_t* c) {
303 const char* p = SVGParse::FindS32(currentPos, c);

Callers 1

parseColorTokenMethod · 0.95

Calls 6

matchHexTokenMethod · 0.95
Uint32ToColorFunction · 0.85
c_strMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected