mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-16 21:20:18 +00:00
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This doesn't exist any more, but did when I submitted the PropertyNameAndID PR. Oops!
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FlyString.h>
|
|
#include <AK/GenericShorthands.h>
|
|
#include <AK/Optional.h>
|
|
#include <LibWeb/CSS/PropertyID.h>
|
|
#include <LibWeb/CSS/PropertyName.h>
|
|
#include <LibWeb/CSS/Serialize.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
class WEB_API PropertyNameAndID {
|
|
public:
|
|
static Optional<PropertyNameAndID> from_name(FlyString name)
|
|
{
|
|
if (is_a_custom_property_name_string(name))
|
|
return PropertyNameAndID(move(name), PropertyID::Custom);
|
|
|
|
if (auto property_id = property_id_from_string(name); property_id.has_value())
|
|
return PropertyNameAndID(string_from_property_id(property_id.value()), property_id.value());
|
|
|
|
return {};
|
|
}
|
|
|
|
static PropertyNameAndID from_id(PropertyID property_id)
|
|
{
|
|
VERIFY(property_id != PropertyID::Custom);
|
|
return PropertyNameAndID({}, property_id);
|
|
}
|
|
|
|
bool is_custom_property() const { return m_property_id == PropertyID::Custom; }
|
|
PropertyID id() const { return m_property_id; }
|
|
|
|
FlyString const& name() const
|
|
{
|
|
if (!m_name.has_value())
|
|
m_name = string_from_property_id(m_property_id);
|
|
return m_name.value();
|
|
}
|
|
|
|
String to_string() const
|
|
{
|
|
return serialize_an_identifier(name());
|
|
}
|
|
|
|
private:
|
|
PropertyNameAndID(Optional<FlyString> name, PropertyID id)
|
|
: m_name(move(name))
|
|
, m_property_id(id)
|
|
{
|
|
}
|
|
|
|
mutable Optional<FlyString> m_name;
|
|
PropertyID m_property_id;
|
|
};
|
|
|
|
}
|