equal
deleted
inserted
replaced
46 |
46 |
47 unsigned long |
47 unsigned long |
48 parseHexColor(const std::string& hex) { |
48 parseHexColor(const std::string& hex) { |
49 size_t count; |
49 size_t count; |
50 unsigned long rgb = std::stoul(hex, &count, 16); |
50 unsigned long rgb = std::stoul(hex, &count, 16); |
51 if (count == 6 || count == 8 && hex.starts_with("0x")) return rgb; |
51 if (count == 6 || (count == 8 && hex.starts_with("0x"))) return rgb; |
52 else throw std::logic_error("Invalid hex color string"); |
52 else throw std::logic_error("Invalid hex color string"); |
53 // the input should be (0x)?[0-9a-fA-F]{6}, however: |
53 // the input should be (0x)?[0-9a-fA-F]{6}, however: |
54 // values like 0x0123 are also accepted and interpreted as 000123 |
54 // values like 0x0123 are also accepted and interpreted as 000123 |
55 // values like +0x012 are also accepted and interpreted as 000012 |
55 // values like +0x012 are also accepted and interpreted as 000012 |
56 } |
56 } |