[Webkit-unassigned] [Bug 247326] Add helper function to match identifiers and return a corresponding enum mapped enum value for CSS property parser

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Nov 1 20:38:59 PDT 2022


https://bugs.webkit.org/show_bug.cgi?id=247326

--- Comment #2 from Sam Weinig <sam at webkit.org> ---
An alternative that doesn't require declaring the static constexprs would be to use initializer_list and a linear search. For example:

```
template<typename MappedType>
static std::optional<typename Map::ValueType> consumeIdentUsingMappingTo(CSSParserTokenRange& range, std::initializer_list<std::pair<CSSValueID, MappedType> list)
{
    auto key = range.peek().id();
    for (auto [valueID, mapping] : list) {
        if (key == valueID)
            return std::make_optional(mapping);
    }
    return std::nullopt;
}

static std::optional<HueInterpolationMethod> consumeHueInterpolationMethod(CSSParserTokenRange& range)
{
    return consumeIdentifierMappingTo<HueInterpolationMethod>(range, {
        { CSSValueShorter, HueInterpolationMethod::Shorter },
        { CSSValueLonger, HueInterpolationMethod::Longer },
        { CSSValueIncreasing, HueInterpolationMethod::Increasing },
        { CSSValueDecreasing, HueInterpolationMethod::Decreasing },
        { CSSValueSpecified, HueInterpolationMethod::Specified },
    });
}
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20221102/91334b49/attachment.htm>


More information about the webkit-unassigned mailing list