[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:37:43 PDT 2022


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

--- Comment #1 from Sam Weinig <sam at webkit.org> ---
One idea is to just use SortedArrayMap + a helper. For example, the helper "consumeIdentUsingMapping" and and example use:

```
template<typename Map>
static std::optional<typename Map::ValueType> consumeIdentUsingMapping(CSSParserTokenRange& range, Map& map)
{
    if (auto value = map.tryGet(range.peek().id())) {
        range.consumeIncludingWhitespace();
        return std::make_optional(*value);
    }
    return std::nullopt;
}

static std::optional<HueInterpolationMethod> consumeHueInterpolationMethod(CSSParserTokenRange& range)
{
    static constexpr std::pair<CSSValueID, HueInterpolationMethod> hueInterpolationMethodMappings[] {
        { CSSValueShorter, HueInterpolationMethod::Shorter },
        { CSSValueLonger, HueInterpolationMethod::Longer },
        { CSSValueIncreasing, HueInterpolationMethod::Increasing },
        { CSSValueDecreasing, HueInterpolationMethod::Decreasing },
        { CSSValueSpecified, HueInterpolationMethod::Specified },
    };
    static constexpr SortedArrayMap hueInterpolationMethodMap { hueInterpolationMethodMappings };

    return consumeIdentUsingMapping(range, hueInterpolationMethodMap);
}
```

-- 
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/24533c73/attachment.htm>


More information about the webkit-unassigned mailing list