-------------------------------------------------------------
| 418 | |
| 419 | //------------------------------------------------------------- |
| 420 | rgba8 parse_color(const char* str) |
| 421 | { |
| 422 | while(*str == ' ') ++str; |
| 423 | unsigned c = 0; |
| 424 | if(*str == '#') |
| 425 | { |
| 426 | sscanf(str + 1, "%x", &c); |
| 427 | return rgb8_packed(c); |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | named_color c; |
| 432 | unsigned len = strlen(str); |
| 433 | if(len > sizeof(c.name) - 1) |
| 434 | { |
| 435 | throw exception("parse_color: Invalid color name '%s'", str); |
| 436 | } |
| 437 | strcpy(c.name, str); |
| 438 | const void* p = bsearch(&c, |
| 439 | colors, |
| 440 | sizeof(colors) / sizeof(colors[0]), |
| 441 | sizeof(colors[0]), |
| 442 | cmp_color); |
| 443 | if(p == 0) |
| 444 | { |
| 445 | throw exception("parse_color: Invalid color name '%s'", str); |
| 446 | } |
| 447 | const named_color* pc = (const named_color*)p; |
| 448 | return rgba8(pc->r, pc->g, pc->b, pc->a); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | double parse_double(const char* str) |
| 453 | { |
no test coverage detected