Files
react-native/packages/react-native/ReactCommon/react/renderer/css/CSSCommaSeparatedList.h
T
Nick GerlemanandFacebook GitHub Bot f77fced5e2 CSSCommaSeparatedList (#48987)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48987

Adds a data type parser for a variable number of values of a given single data type (at least 1).

E.g. `CSSCommaSeparatedList<CSSShadow>` will represent the syntax of `<shadow>#` (ie the value produced by box-shadow).

Changelog: [internal]

Reviewed By: lenaic

Differential Revision: D68738165

fbshipit-source-id: 6dd17b3da24b1c24808e49834a29a237c0115fab
2025-02-04 12:16:40 -08:00

46 lines
1.2 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <optional>
#include <variant>
#include <react/renderer/css/CSSDataType.h>
#include <react/renderer/css/CSSValueParser.h>
namespace facebook::react {
/**
* Represents a comma-separated repetition of a given single type.
* https://www.w3.org/TR/css-values-4/#mult-comma
*/
template <CSSDataType AllowedTypeT>
struct CSSCommaSeparatedList : public std::vector<AllowedTypeT> {};
template <CSSDataType AllowedTypeT>
struct CSSDataTypeParser<CSSCommaSeparatedList<AllowedTypeT>> {
static inline auto consume(CSSSyntaxParser& parser)
-> std::optional<CSSCommaSeparatedList<AllowedTypeT>> {
CSSCommaSeparatedList<AllowedTypeT> result;
for (auto nextValue = parseNextCSSValue<AllowedTypeT>(parser);
!std::holds_alternative<std::monostate>(nextValue);
nextValue =
parseNextCSSValue<AllowedTypeT>(parser, CSSDelimiter::Comma)) {
result.push_back(std::move(std::get<AllowedTypeT>(nextValue)));
}
if (result.empty()) {
return {};
}
return result;
}
};
} // namespace facebook::react