MCPcopy Create free account
hub / github.com/antvis/F2Native / Parse

Method Parse

core/graphics/canvas/CanvasColorParser.cpp:353–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351}
352
353bool CanvasColorParser::Parse(const std::string &str, CanvasColor &outputAgColor) {
354 InitColorMapIfEmpty();
355
356 outputAgColor = {0, 0, 0, 255};
357 if (str.empty()) {
358 return false;
359 }
360
361 bool result = true;
362 const char *value = str.data();
363 do {
364 if (value[0] == '#') {
365 int length = (int) strlen(value);
366 char str_arr[] = "ffffffff";
367
368 // check value valid?
369 bool sharp_valid = true;
370 for (int i = 1; i < length; i++) {
371 if (!((value[i] >= '0' && value[i] <= '9') ||
372 (value[i] >= 'a' && value[i] <= 'f') ||
373 (value[i] >= 'A' && value[i] <= 'F'))) { // wrong format
374 // LOG_E("check # wrong format: %c=", value[i]);
375 sharp_valid = false;
376 break;
377 }
378 }
379
380 if (!sharp_valid) {
381 result = false;
382 break;
383 }
384
385 if (length == 4) {
386 str_arr[0] = str_arr[1] = value[1];
387 str_arr[2] = str_arr[3] = value[2];
388 str_arr[4] = str_arr[5] = value[3];
389 ParseRGBAFullString(str_arr, outputAgColor);
390 } else if (length == 5) {
391 str_arr[0] = str_arr[1] = value[1];
392 str_arr[2] = str_arr[3] = value[2];
393 str_arr[4] = str_arr[5] = value[3];
394 str_arr[6] = str_arr[7] = value[4];
395 ParseRGBAFullString(str_arr, outputAgColor);
396 } else if (length == 7) { // #RRGGBB format
397 str_arr[0] = value[1];
398 str_arr[1] = value[2];
399 str_arr[2] = value[3];
400 str_arr[3] = value[4];
401 str_arr[4] = value[5];
402 str_arr[5] = value[6];
403 ParseRGBAFullString(str_arr, outputAgColor);
404 } else if (length == 9) { // #RRGGBBAA
405 memcpy(str_arr, value + 1, 8);
406 ParseRGBAFullString(str_arr, outputAgColor);
407 } else {
408 result = false;
409 }
410 } else {

Callers

nothing calls this directly

Calls 6

ParseRGBAFullStringFunction · 0.85
HandleBraceRGBAColorFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
findMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected