@@ -269,16 +269,6 @@ void skip_whitespace(const std::string& text, size_t& pos, size_t end){
269
269
}
270
270
}
271
271
272
- uint32_t CSSColorParser::Color::getInt () {
273
- uint32_t color = ((uint32_t )(255.0 * a) << 24 ) + ((uint32_t )b << 16 ) + ((uint32_t )g << 8 ) + ((uint32_t )r);
274
- return color;
275
- }
276
-
277
- Color CSSColorParser::parse (const std::string& css_str) {
278
- bool valid;
279
- return parse (css_str, valid);
280
- }
281
-
282
272
void parseHexRGB (const std::string& css_str, size_t pos, size_t end, bool & matched, bool & valid, Color& color) {
283
273
if (!match (' #' , css_str, pos, end)) {
284
274
return ;
@@ -471,6 +461,16 @@ void parseNamedColor(const std::string& css_str, size_t pos, size_t end, bool& v
471
461
}
472
462
473
463
464
+ uint32_t CSSColorParser::Color::getInt () {
465
+ uint32_t color = ((uint32_t )(255.0 * a) << 24 ) + ((uint32_t )b << 16 ) + ((uint32_t )g << 8 ) + ((uint32_t )r);
466
+ return color;
467
+ }
468
+
469
+ Color CSSColorParser::parse (const std::string& css_str) {
470
+ bool valid;
471
+ return parse (css_str, valid);
472
+ }
473
+
474
474
Color CSSColorParser::parse (const std::string& css_str, bool & valid) {
475
475
valid = false ;
476
476
@@ -484,22 +484,24 @@ Color CSSColorParser::parse(const std::string& css_str, bool& valid) {
484
484
return {};
485
485
}
486
486
487
- parseHexRGB ( css_str, pos, end, matched, valid, color);
488
- if (matched) {
489
- return color;
490
- }
487
+ switch (*( css_str. c_str () + pos)) {
488
+ case ' # ' :
489
+ parseHexRGB (css_str, pos, end, matched, valid, color) ;
490
+ break ;
491
491
492
- parseRGB (css_str, pos, end, matched, valid, color);
493
- if (matched) {
494
- return color;
495
- }
492
+ case ' r ' :
493
+ case ' R ' :
494
+ parseRGB (css_str, pos, end, matched, valid, color) ;
495
+ break ;
496
496
497
- parseHSL (css_str, pos, end, matched, valid, color);
498
- if (matched) {
499
- return color;
497
+ case ' h' :
498
+ case ' H' :
499
+ parseHSL (css_str, pos, end, matched, valid, color);
500
+ break ;
500
501
}
501
502
502
- parseNamedColor (css_str, pos, end, valid, color);
503
+ if (!matched)
504
+ parseNamedColor (css_str, pos, end, valid, color);
503
505
504
506
return color;
505
507
}
0 commit comments