mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 17:29:01 +00:00
LibWeb: Generate a math_function_from_string() function
This will be used as a convenient way to see if a string is the name of a math function.
This commit is contained in:
parent
177395155a
commit
73d7d6b831
Notes:
github-actions[bot]
2025-08-29 09:59:04 +00:00
Author: https://github.com/AtkinsSJ
Commit: 73d7d6b831
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5955
Reviewed-by: https://github.com/trflynn89
1 changed files with 31 additions and 1 deletions
|
@ -22,9 +22,13 @@ ErrorOr<void> generate_header_file(JsonObject& functions_data, Core::File& file)
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Optional.h>
|
||||||
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
enum class MathFunction {
|
enum class MathFunction {
|
||||||
|
Calc,
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
functions_data.for_each_member([&](auto& name, auto&) {
|
functions_data.for_each_member([&](auto& name, auto&) {
|
||||||
|
@ -36,6 +40,8 @@ enum class MathFunction {
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Optional<MathFunction> math_function_from_string(StringView);
|
||||||
|
|
||||||
}
|
}
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
|
@ -87,12 +93,36 @@ ErrorOr<void> generate_implementation_file(JsonObject& functions_data, Core::Fil
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
// This file is generated by GenerateCSSMathFunctions.cpp
|
// This file is generated by GenerateCSSMathFunctions.cpp
|
||||||
|
|
||||||
|
#include <LibWeb/CSS/Enums.h>
|
||||||
#include <LibWeb/CSS/MathFunctions.h>
|
#include <LibWeb/CSS/MathFunctions.h>
|
||||||
#include <LibWeb/CSS/Parser/ErrorReporter.h>
|
#include <LibWeb/CSS/Parser/ErrorReporter.h>
|
||||||
#include <LibWeb/CSS/Parser/Parser.h>
|
#include <LibWeb/CSS/Parser/Parser.h>
|
||||||
#include <LibWeb/CSS/Enums.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||||
|
|
||||||
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
Optional<MathFunction> math_function_from_string(StringView name)
|
||||||
|
{
|
||||||
|
if (name.equals_ignoring_ascii_case("calc"sv))
|
||||||
|
return MathFunction::Calc;
|
||||||
|
)~~~");
|
||||||
|
|
||||||
|
functions_data.for_each_member([&](auto& name, auto&) {
|
||||||
|
auto member_generator = generator.fork();
|
||||||
|
member_generator.set("name:lowercase", name);
|
||||||
|
member_generator.set("name:titlecase", title_casify(name));
|
||||||
|
member_generator.append(R"~~~(
|
||||||
|
if (name.equals_ignoring_ascii_case("@name:lowercase@"sv))
|
||||||
|
return MathFunction::@name:titlecase@;
|
||||||
|
)~~~");
|
||||||
|
});
|
||||||
|
|
||||||
|
generator.append(R"~~~(
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
|
||||||
static Optional<RoundingStrategy> parse_rounding_strategy(Vector<ComponentValue> const& tokens)
|
static Optional<RoundingStrategy> parse_rounding_strategy(Vector<ComponentValue> const& tokens)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue