MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / tryInterpretLength

Method tryInterpretLength

lib/Epub/Epub/css/CssParser.cpp:268–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268bool CssParser::tryInterpretLength(std::string_view val, CssLength& out) {
269 val = trimCssWhitespace(val);
270 if (val.empty()) {
271 out = CssLength{};
272 return false;
273 }
274
275 size_t unitStart = val.size();
276 for (size_t i = 0; i < val.size(); ++i) {
277 const char c = val[i];
278 if (!std::isdigit(c) && c != '.' && c != '-' && c != '+') {
279 unitStart = i;
280 break;
281 }
282 }
283
284 float numericValue;
285 if (!tryParseNumber(val.substr(0, unitStart), numericValue)) {
286 out = CssLength{};
287 return false; // No number parsed (e.g. auto, inherit, initial)
288 }
289
290 const std::string_view unitPart = val.substr(unitStart);
291 auto unit = CssUnit::Pixels;
292 if (iequalsAscii(unitPart, "em")) {
293 unit = CssUnit::Em;
294 } else if (iequalsAscii(unitPart, "rem")) {
295 unit = CssUnit::Rem;
296 } else if (iequalsAscii(unitPart, "pt")) {
297 unit = CssUnit::Points;
298 } else if (unitPart == "%") {
299 unit = CssUnit::Percent;
300 }
301
302 out = CssLength{numericValue, unit};
303 return true;
304}
305
306// Declaration parsing
307

Callers

nothing calls this directly

Calls 5

trimCssWhitespaceFunction · 0.85
tryParseNumberFunction · 0.85
iequalsAsciiFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected