summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-10-24 15:10:00 +0100
committerAndreas Kling <kling@serenityos.org>2021-10-24 22:12:35 +0200
commit094dc04695699b93085a0907d6b52c5a43b156dd (patch)
treeba921a0b7547cf0203500104c3e15c9f3009b580
parent639c913e58c350592fbead18a7991c74e782d7b5 (diff)
downloadserenity-094dc04695699b93085a0907d6b52c5a43b156dd.zip
LibGfx: Make Color::from_string() case-insensitive
This function implements CSS color syntax, which is case-insensitive in HTML contexts. Making it insensitive here means not having to remember to do it in every user, (many of the HTML elements do not do this,) and means they don't have to produce a lowercase copy of the input string before passing it.
-rw-r--r--Userland/Libraries/LibGfx/Color.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp
index 75af331380..2c2a288a81 100644
--- a/Userland/Libraries/LibGfx/Color.cpp
+++ b/Userland/Libraries/LibGfx/Color.cpp
@@ -30,7 +30,7 @@ String Color::to_string_without_alpha() const
static Optional<Color> parse_rgb_color(StringView const& string)
{
- VERIFY(string.starts_with("rgb("));
+ VERIFY(string.starts_with("rgb(", CaseSensitivity::CaseInsensitive));
VERIFY(string.ends_with(")"));
auto substring = string.substring_view(4, string.length() - 5);
@@ -51,7 +51,7 @@ static Optional<Color> parse_rgb_color(StringView const& string)
static Optional<Color> parse_rgba_color(StringView const& string)
{
- VERIFY(string.starts_with("rgba("));
+ VERIFY(string.starts_with("rgba(", CaseSensitivity::CaseInsensitive));
VERIFY(string.ends_with(")"));
auto substring = string.substring_view(5, string.length() - 6);
@@ -245,18 +245,18 @@ Optional<Color> Color::from_string(StringView const& string)
{ 0x000000, nullptr }
};
- if (string == "transparent")
+ if (string.equals_ignoring_case("transparent"))
return Color::from_rgba(0x00000000);
for (size_t i = 0; !web_colors[i].name.is_null(); ++i) {
- if (string == web_colors[i].name)
+ if (string.equals_ignoring_case(web_colors[i].name))
return Color::from_rgb(web_colors[i].color);
}
- if (string.starts_with("rgb(") && string.ends_with(")"))
+ if (string.starts_with("rgb(", CaseSensitivity::CaseInsensitive) && string.ends_with(")"))
return parse_rgb_color(string);
- if (string.starts_with("rgba(") && string.ends_with(")"))
+ if (string.starts_with("rgba(", CaseSensitivity::CaseInsensitive) && string.ends_with(")"))
return parse_rgba_color(string);
if (string[0] != '#')