MCPcopy Create free account
hub / github.com/apache/trafficserver / ScanScalar

Function ScanScalar

lib/yamlcpp/src/scanscalar.cpp:21–250  ·  view source on GitHub ↗

ScanScalar . This is where the scalar magic happens. . We do the scanning in three phases: 1. Scan until newline 2. Eat newline 3. Scan leading blanks. . Depending on the parameters given, we store or stop and different places in the above flow.

Source from the content-addressed store, hash-verified

19// . Depending on the parameters given, we store or stop
20// and different places in the above flow.
21std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
22 bool foundNonEmptyLine = false;
23 bool pastOpeningBreak = (params.fold == FOLD_FLOW);
24 bool emptyLine = false, moreIndented = false;
25 int foldedNewlineCount = 0;
26 bool foldedNewlineStartedMoreIndented = false;
27 std::size_t lastEscapedChar = std::string::npos;
28 std::string scalar;
29 params.leadingSpaces = false;
30
31 if (!params.end) {
32 params.end = &Exp::Empty();
33 }
34
35 while (INPUT) {
36 // ********************************
37 // Phase #1: scan until line ending
38
39 std::size_t lastNonWhitespaceChar = scalar.size();
40 bool escapedNewline = false;
41 while (!params.end->Matches(INPUT) && !Exp::Break().Matches(INPUT)) {
42 if (!INPUT) {
43 break;
44 }
45
46 // document indicator?
47 if (INPUT.column() == 0 && Exp::DocIndicator().Matches(INPUT)) {
48 if (params.onDocIndicator == BREAK) {
49 break;
50 }
51 if (params.onDocIndicator == THROW) {
52 throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
53 }
54 }
55
56 foundNonEmptyLine = true;
57 pastOpeningBreak = true;
58
59 // escaped newline? (only if we're escaping on slash)
60 if (params.escape == '\\' && Exp::EscBreak().Matches(INPUT)) {
61 // eat escape character and get out (but preserve trailing whitespace!)
62 INPUT.get();
63 lastNonWhitespaceChar = scalar.size();
64 lastEscapedChar = scalar.size();
65 escapedNewline = true;
66 break;
67 }
68
69 // escape this?
70 if (INPUT.peek() == params.escape) {
71 scalar += Exp::Escape(INPUT);
72 lastNonWhitespaceChar = scalar.size();
73 lastEscapedChar = scalar.size();
74 continue;
75 }
76
77 // otherwise, just add the damn character
78 char ch = INPUT.get();

Callers 3

ScanPlainScalarMethod · 0.85
ScanQuotedScalarMethod · 0.85
ScanBlockScalarMethod · 0.85

Calls 12

ParserExceptionFunction · 0.85
stringClass · 0.85
MatchesMethod · 0.80
peekMethod · 0.80
eatMethod · 0.80
EscapeFunction · 0.70
sizeMethod · 0.45
columnMethod · 0.45
markMethod · 0.45
getMethod · 0.45
MatchMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected