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

Method loadFromStream

lib/Epub/Epub/css/CssParser.cpp:488–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486// Main parsing entry point
487
488bool CssParser::loadFromStream(HalFile& source) {
489 if (!source) {
490 LOG_ERR("CSS", "Cannot read from invalid file");
491 return false;
492 }
493
494 size_t totalRead = 0;
495
496 // Use stack-allocated buffers for parsing to avoid heap reallocations
497 StackBuffer selector;
498 StackBuffer declBuffer;
499
500 bool inComment = false;
501 bool maybeSlash = false;
502 bool prevStar = false;
503
504 bool inAtRule = false;
505 int atDepth = 0;
506
507 int bodyDepth = 0;
508 bool skippingRule = false;
509 CssStyle currentStyle;
510
511 auto handleChar = [&](const char c) {
512 if (inAtRule) {
513 if (c == '{') {
514 ++atDepth;
515 } else if (c == '}') {
516 if (atDepth > 0) --atDepth;
517 if (atDepth == 0) inAtRule = false;
518 } else if (c == ';' && atDepth == 0) {
519 inAtRule = false;
520 }
521 return;
522 }
523
524 if (bodyDepth == 0) {
525 if (selector.empty() && isCssWhitespace(c)) {
526 return;
527 }
528 if (c == '@' && selector.empty()) {
529 inAtRule = true;
530 atDepth = 0;
531 return;
532 }
533 if (c == '{') {
534 bodyDepth = 1;
535 currentStyle = CssStyle{};
536 declBuffer.clear();
537 if (selector.size() > MAX_SELECTOR_LENGTH * 4) {
538 skippingRule = true;
539 }
540 return;
541 }
542 selector.push_back(c);
543 return;
544 }
545

Callers 1

parseCssFilesMethod · 0.80

Calls 7

isCssWhitespaceFunction · 0.85
push_backMethod · 0.80
emptyMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
availableMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected