color_t: accept leading #
for hex string input
This commit is contained in:
parent
c48121ce05
commit
c8a47c0bca
1 changed files with 5 additions and 1 deletions
|
@ -63,8 +63,12 @@ color_t color_t::from_rgb_string(std::string_view c)
|
|||
|
||||
color_t color_t::from_hex_string(std::string_view c)
|
||||
{
|
||||
if(c[0] == '#') {
|
||||
c = c.substr(1);
|
||||
}
|
||||
|
||||
if(c.length() != 6) {
|
||||
throw std::invalid_argument("Color hex string should be exactly 6 digits");
|
||||
throw std::invalid_argument("Color hex string should be exactly 6 digits (leading '#' optional)");
|
||||
}
|
||||
|
||||
if(std::any_of(c.begin(), c.end(), [](const char& ch) { return std::isxdigit(ch) == 0; })) {
|
||||
|
|
Loading…
Add table
Reference in a new issue