mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibWeb: Extract CalculationNode::constant_type_from_string() function
This is needed by some upcoming generated code. Renamed "PI" member to "Pi" while I was at it.
This commit is contained in:
parent
e4a2bd7a44
commit
136dc7a1c3
Notes:
sideshowbarker
2024-07-17 07:16:27 +09:00
Author: https://github.com/AtkinsSJ
Commit: 136dc7a1c3
Pull-request: https://github.com/SerenityOS/serenity/pull/19996
3 changed files with 27 additions and 25 deletions
|
@ -87,6 +87,26 @@ static CalculatedStyleValue::CalculationResult to_resolved_type(CalculatedStyleV
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Optional<CalculationNode::ConstantType> CalculationNode::constant_type_from_string(StringView string)
|
||||
{
|
||||
if (string.equals_ignoring_ascii_case("e"sv))
|
||||
return CalculationNode::ConstantType::E;
|
||||
|
||||
if (string.equals_ignoring_ascii_case("pi"sv))
|
||||
return CalculationNode::ConstantType::Pi;
|
||||
|
||||
if (string.equals_ignoring_ascii_case("infinity"sv))
|
||||
return CalculationNode::ConstantType::Infinity;
|
||||
|
||||
if (string.equals_ignoring_ascii_case("-infinity"sv))
|
||||
return CalculationNode::ConstantType::MinusInfinity;
|
||||
|
||||
if (string.equals_ignoring_ascii_case("NaN"sv))
|
||||
return CalculationNode::ConstantType::NaN;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
CalculationNode::CalculationNode(Type type)
|
||||
: m_type(type)
|
||||
{
|
||||
|
@ -974,7 +994,7 @@ ErrorOr<String> ConstantCalculationNode::to_string() const
|
|||
switch (m_constant) {
|
||||
case CalculationNode::ConstantType::E:
|
||||
return "e"_short_string;
|
||||
case CalculationNode::ConstantType::PI:
|
||||
case CalculationNode::ConstantType::Pi:
|
||||
return "pi"_short_string;
|
||||
case CalculationNode::ConstantType::Infinity:
|
||||
return "infinity"_string;
|
||||
|
@ -1005,7 +1025,7 @@ CalculatedStyleValue::CalculationResult ConstantCalculationNode::resolve([[maybe
|
|||
switch (m_constant) {
|
||||
case CalculationNode::ConstantType::E:
|
||||
return { Number(Number::Type::Number, M_E) };
|
||||
case CalculationNode::ConstantType::PI:
|
||||
case CalculationNode::ConstantType::Pi:
|
||||
return { Number(Number::Type::Number, M_PI) };
|
||||
// FIXME: We need to keep track of Infinity and NaN across all nodes, since they require special handling.
|
||||
case CalculationNode::ConstantType::Infinity:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue