mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 08:08:43 +00:00
LibGfx: Factor out #rrggbb Color parsing into its own helper function
This commit is contained in:
parent
3c5e3eef10
commit
cf42bf2bca
Notes:
github-actions[bot]
2024-07-31 00:39:35 +00:00
Author: https://github.com/ADKaster
Commit: cf42bf2bca
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/821
1 changed files with 53 additions and 49 deletions
|
@ -262,12 +262,8 @@ Optional<Color> Color::from_named_css_color_string(StringView string)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Color> Color::from_string(StringView string)
|
static Optional<Color> hex_string_to_color(StringView string)
|
||||||
{
|
{
|
||||||
if (string.is_empty())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
if (string[0] == '#') {
|
|
||||||
auto hex_nibble_to_u8 = [](char nibble) -> Optional<u8> {
|
auto hex_nibble_to_u8 = [](char nibble) -> Optional<u8> {
|
||||||
if (!isxdigit(nibble))
|
if (!isxdigit(nibble))
|
||||||
return {};
|
return {};
|
||||||
|
@ -317,6 +313,14 @@ Optional<Color> Color::from_string(StringView string)
|
||||||
return Color(r.value(), g.value(), b.value(), a.value());
|
return Color(r.value(), g.value(), b.value(), a.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<Color> Color::from_string(StringView string)
|
||||||
|
{
|
||||||
|
if (string.is_empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (string[0] == '#')
|
||||||
|
return hex_string_to_color(string);
|
||||||
|
|
||||||
if (string.starts_with("rgb("sv, CaseSensitivity::CaseInsensitive) && string.ends_with(')'))
|
if (string.starts_with("rgb("sv, CaseSensitivity::CaseInsensitive) && string.ends_with(')'))
|
||||||
return parse_rgb_color(string);
|
return parse_rgb_color(string);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue