mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
36ff6187f6
"The official project language is American English […]."
5d2e915623/CONTRIBUTING.md (L30)
Here's a short statistic of the occurrences of the word "behavio(u)r":
$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
2 BEHAVIOR
24 Behaviour
32 behaviour
407 Behavior
992 behavior
Therefore, it is clear that "behaviour" (56 occurrences) should be
regarded a typo, and "behavior" (1401 occurrences) should be preferred.
Note that The occurrences in LibJS are intentionally NOT changed,
because there are taken verbatim from the specification. Hence:
$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
2 BEHAVIOR
10 behaviour
24 Behaviour
407 Behavior
1014 behavior
103 lines
3.2 KiB
C++
103 lines
3.2 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
|
|
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/JsonValue.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <LibGUI/Icon.h>
|
|
#include <LibGUI/Variant.h>
|
|
|
|
namespace GUI {
|
|
|
|
Variant::Variant(JsonValue const& value)
|
|
{
|
|
*this = value;
|
|
}
|
|
|
|
Variant& Variant::operator=(JsonValue const& value)
|
|
{
|
|
if (value.is_null())
|
|
return *this;
|
|
|
|
if (value.is_i32()) {
|
|
set(value.as_i32());
|
|
return *this;
|
|
}
|
|
|
|
if (value.is_u32()) {
|
|
set(value.as_u32());
|
|
return *this;
|
|
}
|
|
|
|
if (value.is_i64()) {
|
|
set(value.as_i64());
|
|
return *this;
|
|
}
|
|
|
|
if (value.is_u64()) {
|
|
set(value.as_u64());
|
|
return *this;
|
|
}
|
|
|
|
if (value.is_string()) {
|
|
set(value.as_string());
|
|
return *this;
|
|
}
|
|
|
|
if (value.is_bool()) {
|
|
set(Detail::Boolean { value.as_bool() });
|
|
return *this;
|
|
}
|
|
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
|
|
bool Variant::operator==(Variant const& other) const
|
|
{
|
|
return visit([&]<typename T>(T const& own_value) {
|
|
return other.visit(
|
|
[&](T const& other_value) -> bool {
|
|
if constexpr (requires { own_value == other_value; })
|
|
return own_value == other_value;
|
|
else if constexpr (IsSame<T, GUI::Icon>)
|
|
return &own_value.impl() == &other_value.impl();
|
|
// FIXME: Figure out if this silly behavior is actually used anywhere, then get rid of it.
|
|
else
|
|
return to_deprecated_string() == other.to_deprecated_string();
|
|
},
|
|
[&](auto const&) {
|
|
// FIXME: Figure out if this silly behavior is actually used anywhere, then get rid of it.
|
|
return to_deprecated_string() == other.to_deprecated_string();
|
|
});
|
|
});
|
|
}
|
|
|
|
bool Variant::operator<(Variant const& other) const
|
|
{
|
|
return visit([&]<typename T>(T const& own_value) {
|
|
return other.visit(
|
|
[&](T const& other_value) -> bool {
|
|
// FIXME: Maybe compare icons somehow differently?
|
|
if constexpr (IsSame<T, GUI::Icon>)
|
|
return &own_value.impl() < &other_value.impl();
|
|
// FIXME: Maybe compare bitmaps somehow differently?
|
|
else if constexpr (IsSame<T, NonnullRefPtr<Gfx::Bitmap>>)
|
|
return own_value.ptr() < other_value.ptr();
|
|
else if constexpr (IsSame<T, NonnullRefPtr<Gfx::Font>>)
|
|
return own_value->name() < other_value->name();
|
|
else if constexpr (requires { own_value < other_value; })
|
|
return own_value < other_value;
|
|
// FIXME: Figure out if this silly behavior is actually used anywhere, then get rid of it.
|
|
else
|
|
return to_deprecated_string() < other.to_deprecated_string();
|
|
},
|
|
[&](auto const&) -> bool {
|
|
return to_deprecated_string() < other.to_deprecated_string(); // FIXME: Figure out if this silly behavior is actually used anywhere, then get rid of it.
|
|
});
|
|
});
|
|
}
|
|
}
|