Skip to content

Commit 4c733b9

Browse files
committed
refactor: adjust CSSCalc formatting
1 parent 12696b2 commit 4c733b9

1 file changed

Lines changed: 62 additions & 39 deletions

File tree

  • packages/react-native/ReactCommon/react/renderer/css

packages/react-native/ReactCommon/react/renderer/css/CSSCalc.h

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ struct CSSCalc {
3232
float vh{0.0f};
3333
bool unitless{false};
3434

35-
constexpr auto operator==(const CSSCalc& rhs) const -> bool = default;
35+
constexpr bool operator==(const CSSCalc &rhs) const = default;
3636

37-
constexpr auto operator+(const CSSCalc& rhs) const -> CSSCalc {
37+
constexpr CSSCalc operator+(const CSSCalc &rhs) const ->
38+
{
3839
return CSSCalc{
3940
px + rhs.px,
4041
percent + rhs.percent,
@@ -43,7 +44,8 @@ struct CSSCalc {
4344
unitless && rhs.unitless};
4445
}
4546

46-
constexpr auto operator-(const CSSCalc& rhs) const -> CSSCalc {
47+
constexpr CSSCalc operator-(const CSSCalc &rhs) const
48+
{
4749
return CSSCalc{
4850
px - rhs.px,
4951
percent - rhs.percent,
@@ -52,67 +54,80 @@ struct CSSCalc {
5254
unitless && rhs.unitless};
5355
}
5456

55-
constexpr auto operator*(float scalar) const -> CSSCalc {
57+
constexpr CSSCalc operator*(float scalar) const
58+
{
5659
return CSSCalc{
5760
px * scalar, percent * scalar, vw * scalar, vh * scalar, unitless};
5861
}
5962

60-
constexpr auto operator/(float scalar) const -> CSSCalc {
63+
constexpr CSSCalc operator/(float scalar) const
64+
{
6165
if (scalar == 0.0f) {
6266
return CSSCalc{};
6367
}
6468
return CSSCalc{
6569
px / scalar, percent / scalar, vw / scalar, vh / scalar, unitless};
6670
}
6771

68-
constexpr auto operator-() const -> CSSCalc {
72+
constexpr CSSCalc operator-() const
73+
{
6974
return CSSCalc{-px, -percent, -vw, -vh, unitless};
7075
}
7176

72-
auto resolve(float percentRef, float viewportWidth, float viewportHeight)
73-
const -> float {
77+
float resolve(float percentRef, float viewportWidth, float viewportHeight)
78+
const
79+
{
7480
return px + (percent * percentRef * 0.01f) + (vw * viewportWidth * 0.01f) +
7581
(vh * viewportHeight * 0.01f);
7682
}
7783

78-
constexpr auto isUnitless() const -> bool {
84+
constexpr bool isUnitless() const
85+
{
7986
return unitless;
8087
}
8188

82-
constexpr auto isPointsOnly() const -> bool {
89+
constexpr bool isPointsOnly() const
90+
{
8391
return percent == 0.0f && vw == 0.0f && vh == 0.0f && !unitless;
8492
}
8593

86-
constexpr auto isPercentOnly() const -> bool {
94+
constexpr bool isPercentOnly() const
95+
{
8796
return px == 0.0f && vw == 0.0f && vh == 0.0f && !unitless;
8897
}
8998

90-
constexpr auto isZero() const -> bool {
99+
constexpr bool isZero() const
100+
{
91101
return px == 0.0f && percent == 0.0f && vw == 0.0f && vh == 0.0f;
92102
}
93103

94-
static constexpr auto fromNumber(float value) -> CSSCalc {
104+
static constexpr CSSCalc fromNumber(float value)
105+
{
95106
return CSSCalc{value, 0.0f, 0.0f, 0.0f, true};
96107
}
97108

98-
static constexpr auto fromPoints(float value) -> CSSCalc {
109+
static constexpr CSSCalc fromPoints(float value)
110+
{
99111
return CSSCalc{value, 0.0f, 0.0f, 0.0f, false};
100112
}
101113

102-
static constexpr auto fromPercent(float value) -> CSSCalc {
114+
static constexpr CSSCalc fromPercent(float value)
115+
{
103116
return CSSCalc{0.0f, value, 0.0f, 0.0f, false};
104117
}
105118

106-
static constexpr auto fromVw(float value) -> CSSCalc {
119+
static constexpr CSSCalc fromVw(float value)
120+
{
107121
return CSSCalc{0.0f, 0.0f, value, 0.0f, false};
108122
}
109123

110-
static constexpr auto fromVh(float value) -> CSSCalc {
124+
static constexpr CSSCalc fromVh(float value)
125+
{
111126
return CSSCalc{0.0f, 0.0f, 0.0f, value, false};
112127
}
113128

114-
static constexpr auto fromLength(float value, CSSLengthUnit unit)
115-
-> std::optional<CSSCalc> {
129+
static constexpr std::optional<CSSCalc> fromLength(float value, CSSLengthUnit unit)
130+
{
116131
switch (unit) {
117132
case CSSLengthUnit::Px:
118133
return fromPoints(value);
@@ -129,26 +144,29 @@ struct CSSCalc {
129144
template <>
130145
struct CSSDataTypeParser<CSSCalc> {
131146
static constexpr auto consumeFunctionBlock(
132-
const CSSFunctionBlock& func,
133-
CSSValueParser& parser) -> std::optional<CSSCalc> {
147+
const CSSFunctionBlock &func,
148+
CSSValueParser &parser) -> std::optional<CSSCalc>
149+
{
134150
if (!iequals(func.name, "calc")) {
135151
return std::nullopt;
136152
}
137153

138154
return parseCalcExpression(parser);
139155
}
140156

141-
static constexpr auto parseCalcExpression(CSSValueParser& parser)
142-
-> std::optional<CSSCalc> {
157+
static constexpr auto parseCalcExpression(CSSValueParser &parser)
158+
-> std::optional<CSSCalc>
159+
{
143160
parser.syntaxParser().consumeWhitespace();
144161
auto result = parseAddSub(parser);
145162
parser.syntaxParser().consumeWhitespace();
146163
return result;
147164
}
148165

149166
static constexpr auto consumeSimpleBlock(
150-
const CSSSimpleBlock& block,
151-
CSSValueParser& parser) -> std::optional<CSSCalc> {
167+
const CSSSimpleBlock &block,
168+
CSSValueParser &parser) -> std::optional<CSSCalc>
169+
{
152170
if (block.openBracketType != CSSTokenType::OpenParen) {
153171
return std::nullopt;
154172
}
@@ -157,8 +175,9 @@ struct CSSDataTypeParser<CSSCalc> {
157175
}
158176

159177
private:
160-
static constexpr auto parseAddSub(CSSValueParser& parser)
161-
-> std::optional<CSSCalc> {
178+
static constexpr auto parseAddSub(CSSValueParser &parser)
179+
-> std::optional<CSSCalc>
180+
{
162181
auto left = parseMulDiv(parser);
163182
if (!left) {
164183
return std::nullopt;
@@ -170,7 +189,7 @@ struct CSSDataTypeParser<CSSCalc> {
170189

171190
auto opResult =
172191
parser.syntaxParser().consumeComponentValue<std::optional<char>>(
173-
CSSDelimiter::None, [](const CSSPreservedToken& token) {
192+
CSSDelimiter::None, [](const CSSPreservedToken &token) {
174193
if (token.type() == CSSTokenType::Delim) {
175194
auto sv = token.stringValue();
176195
if (!sv.empty() && (sv[0] == '+' || sv[0] == '-')) {
@@ -205,8 +224,9 @@ struct CSSDataTypeParser<CSSCalc> {
205224
return left;
206225
}
207226

208-
static constexpr auto parseMulDiv(CSSValueParser& parser)
209-
-> std::optional<CSSCalc> {
227+
static constexpr auto parseMulDiv(CSSValueParser &parser)
228+
-> std::optional<CSSCalc>
229+
{
210230
auto left = parseUnary(parser);
211231
if (!left) {
212232
return std::nullopt;
@@ -218,7 +238,7 @@ struct CSSDataTypeParser<CSSCalc> {
218238

219239
auto opResult =
220240
parser.syntaxParser().consumeComponentValue<std::optional<char>>(
221-
CSSDelimiter::None, [](const CSSPreservedToken& token) {
241+
CSSDelimiter::None, [](const CSSPreservedToken &token) {
222242
if (token.type() == CSSTokenType::Delim) {
223243
auto sv = token.stringValue();
224244
if (!sv.empty() && (sv[0] == '*' || sv[0] == '/')) {
@@ -259,13 +279,14 @@ struct CSSDataTypeParser<CSSCalc> {
259279
return left;
260280
}
261281

262-
static constexpr auto parseUnary(CSSValueParser& parser)
263-
-> std::optional<CSSCalc> {
282+
static constexpr auto parseUnary(CSSValueParser &parser)
283+
-> std::optional<CSSCalc>
284+
{
264285
auto savedParser = parser.syntaxParser();
265286

266287
auto opResult =
267288
parser.syntaxParser().consumeComponentValue<std::optional<char>>(
268-
CSSDelimiter::None, [](const CSSPreservedToken& token) {
289+
CSSDelimiter::None, [](const CSSPreservedToken &token) {
269290
if (token.type() == CSSTokenType::Delim) {
270291
auto sv = token.stringValue();
271292
if (!sv.empty() && (sv[0] == '+' || sv[0] == '-')) {
@@ -288,8 +309,9 @@ struct CSSDataTypeParser<CSSCalc> {
288309
return parsePrimary(parser);
289310
}
290311

291-
static constexpr auto parsePrimary(CSSValueParser& parser)
292-
-> std::optional<CSSCalc> {
312+
static constexpr auto parsePrimary(CSSValueParser &parser)
313+
-> std::optional<CSSCalc>
314+
{
293315
auto value =
294316
parser.parseNextValue<CSSNumber, CSSPercentage, CSSLength, CSSCalc>();
295317

@@ -302,7 +324,7 @@ struct CSSDataTypeParser<CSSCalc> {
302324
}
303325

304326
if (std::holds_alternative<CSSLength>(value)) {
305-
const auto& length = std::get<CSSLength>(value);
327+
const auto &length = std::get<CSSLength>(value);
306328
return CSSCalc::fromLength(length.value, length.unit);
307329
}
308330

@@ -313,8 +335,9 @@ struct CSSDataTypeParser<CSSCalc> {
313335
return std::nullopt;
314336
}
315337

316-
static constexpr auto parseCalcContents(CSSValueParser& parser)
317-
-> std::optional<CSSCalc> {
338+
static constexpr auto parseCalcContents(CSSValueParser &parser)
339+
-> std::optional<CSSCalc>
340+
{
318341
parser.syntaxParser().consumeWhitespace();
319342
auto result = parseAddSub(parser);
320343
parser.syntaxParser().consumeWhitespace();

0 commit comments

Comments
 (0)