MCPcopy Create free account
hub / github.com/AGenUI/AGenUI / parseSingleValue

Function parseSingleValue

core/src/style_parser/agenui_edge_insets_parser.cpp:147–208  ·  view source on GitHub ↗

Parse a single edge value token into EdgeInsetValue.

Source from the content-addressed store, hash-verified

145
146// Parse a single edge value token into EdgeInsetValue.
147static bool parseSingleValue(const std::string& token, EdgeInsetValue& result) {
148 initEdgeInsetValue(result);
149
150 std::string trimmed = trimWhitespace(token);
151 if (trimmed.empty()) {
152 return false;
153 }
154
155 // "auto" keyword
156 if (toLower(trimmed) == "auto") {
157 result.unit = EdgeInsetUnit::Auto;
158 return true;
159 }
160
161 // calc() expression
162 if (isCalcExpression(trimmed)) {
163 std::string expr;
164 if (!extractCalcExpr(trimmed, expr)) {
165 return false;
166 }
167 result.isCalc = true;
168 result.calcExpr = expr;
169 return true;
170 }
171
172 // Percentage: e.g. "50%", "-10%"
173 if (!trimmed.empty() && trimmed.back() == '%') {
174 std::string numStr = trimmed.substr(0, trimmed.size() - 1);
175 float val = 0.0f;
176 if (!parseStrictFloat(numStr, val)) {
177 return false;
178 }
179 result.value = val;
180 result.unit = EdgeInsetUnit::Percent;
181 return true;
182 }
183
184 // Try matching known unit suffixes (longest match first)
185 std::string lower = toLower(trimmed);
186 for (size_t u = 0; u < kUnitTableSize; ++u) {
187 const UnitEntry& entry = kUnitTable[u];
188 if (lower.size() > entry.len && lower.substr(lower.size() - entry.len) == entry.suffix) {
189 std::string numStr = trimmed.substr(0, trimmed.size() - entry.len);
190 float val = 0.0f;
191 if (!parseStrictFloat(numStr, val)) {
192 return false;
193 }
194 result.value = val;
195 result.unit = entry.unit;
196 return true;
197 }
198 }
199
200 // Unitless number: treated as px (e.g. "10", "-3.5", "0")
201 float val = 0.0f;
202 if (!parseStrictFloat(trimmed, val)) {
203 return false;
204 }

Callers 1

parseMethod · 0.85

Calls 8

initEdgeInsetValueFunction · 0.85
toLowerFunction · 0.85
extractCalcExprFunction · 0.85
parseStrictFloatFunction · 0.85
emptyMethod · 0.80
trimWhitespaceFunction · 0.70
isCalcExpressionFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected