21 bool foundNonEmptyLine =
false;
23 bool emptyLine =
false, moreIndented =
false;
24 int foldedNewlineCount = 0;
25 bool foldedNewlineStartedMoreIndented =
false;
26 std::size_t lastEscapedChar = std::string::npos;
34 std::size_t lastNonWhitespaceChar = scalar.size();
35 bool escapedNewline =
false;
48 foundNonEmptyLine =
true;
49 pastOpeningBreak =
true;
55 lastNonWhitespaceChar = scalar.size();
56 lastEscapedChar = scalar.size();
57 escapedNewline =
true;
64 lastNonWhitespaceChar = scalar.size();
65 lastEscapedChar = scalar.size();
70 char ch = INPUT.
get();
72 if(ch !=
' ' && ch !=
'\t')
73 lastNonWhitespaceChar = scalar.size();
97 scalar.erase(lastNonWhitespaceChar);
130 if(params.
fold ==
FOLD_BLOCK && foldedNewlineCount == 0 && nextEmptyLine)
131 foldedNewlineStartedMoreIndented = moreIndented;
134 if(pastOpeningBreak) {
135 switch(params.
fold) {
140 if(!emptyLine && !nextEmptyLine && !moreIndented && !nextMoreIndented && INPUT.
column() >= params.
indent)
142 else if(nextEmptyLine)
143 foldedNewlineCount++;
147 if(!nextEmptyLine && foldedNewlineCount > 0) {
148 scalar +=
std::string(foldedNewlineCount - 1,
'\n');
149 if(foldedNewlineStartedMoreIndented || nextMoreIndented | !foundNonEmptyLine)
151 foldedNewlineCount = 0;
157 else if(!emptyLine && !nextEmptyLine && !escapedNewline)
163 emptyLine = nextEmptyLine;
164 moreIndented = nextMoreIndented;
165 pastOpeningBreak =
true;
176 std::size_t pos = scalar.find_last_not_of(
' ');
177 if(lastEscapedChar != std::string::npos) {
178 if(pos < lastEscapedChar || pos == std::string::npos)
179 pos = lastEscapedChar;
181 if(pos < scalar.size())
182 scalar.erase(pos + 1);
185 switch(params.
chomp) {
187 std::size_t pos = scalar.find_last_not_of(
'\n');
188 if(lastEscapedChar != std::string::npos) {
189 if(pos < lastEscapedChar || pos == std::string::npos)
190 pos = lastEscapedChar;
192 if(pos == std::string::npos)
194 else if(pos + 1 < scalar.size())
195 scalar.erase(pos + 2);
198 std::size_t pos = scalar.find_last_not_of(
'\n');
199 if(lastEscapedChar != std::string::npos) {
200 if(pos < lastEscapedChar || pos == std::string::npos)
201 pos = lastEscapedChar;
203 if(pos == std::string::npos)
205 else if(pos < scalar.size())
206 scalar.erase(pos + 1);