LibWeb/CSS: Implement product_of_two_unit_maps()

Helper function for combining two UnitMaps.
This commit is contained in:
Sam Atkins 2025-09-11 15:58:10 +01:00 committed by Jelle Raaijmakers
commit 5a42b7a40f
Notes: github-actions[bot] 2025-09-12 11:47:03 +00:00
2 changed files with 18 additions and 0 deletions

View file

@ -16,6 +16,23 @@
namespace Web::CSS { namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#product-of-two-unit-maps
UnitMap product_of_two_unit_maps(UnitMap const& units1, UnitMap const& units2)
{
// 1. Let result be a copy of units1.
auto result = units1;
// 2. For each unit → power in units2:
for (auto const& [unit, power] : units2) {
// 1. If result[unit] exists, increment result[unit] by power.
// 2. Otherwise, set result[unit] to power.
result.ensure(unit) += power;
}
// 3. Return result.
return result;
}
Optional<NumericType::BaseType> NumericType::base_type_from_value_type(ValueType value_type) Optional<NumericType::BaseType> NumericType::base_type_from_value_type(ValueType value_type)
{ {
switch (value_type) { switch (value_type) {

View file

@ -14,6 +14,7 @@
namespace Web::CSS { namespace Web::CSS {
using UnitMap = HashMap<FlyString, i32>; using UnitMap = HashMap<FlyString, i32>;
UnitMap product_of_two_unit_maps(UnitMap const&, UnitMap const&);
// https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-type // https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-type
class NumericType { class NumericType {