mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Fixed newlines in folded scalars bug
This commit is contained in:
@@ -21,6 +21,8 @@ namespace YAML
|
|||||||
{
|
{
|
||||||
bool foundNonEmptyLine = false, pastOpeningBreak = false;
|
bool foundNonEmptyLine = false, pastOpeningBreak = false;
|
||||||
bool emptyLine = false, moreIndented = false;
|
bool emptyLine = false, moreIndented = false;
|
||||||
|
int foldedNewlineCount = 0;
|
||||||
|
bool foldedNewlineStartedMoreIndented = false;
|
||||||
std::string scalar;
|
std::string scalar;
|
||||||
params.leadingSpaces = false;
|
params.leadingSpaces = false;
|
||||||
|
|
||||||
@@ -109,13 +111,27 @@ namespace YAML
|
|||||||
// was this an empty line?
|
// was this an empty line?
|
||||||
bool nextEmptyLine = Exp::Break.Matches(INPUT);
|
bool nextEmptyLine = Exp::Break.Matches(INPUT);
|
||||||
bool nextMoreIndented = (INPUT.peek() == ' ');
|
bool nextMoreIndented = (INPUT.peek() == ' ');
|
||||||
|
if(params.fold && foldedNewlineCount == 0 && nextEmptyLine)
|
||||||
|
foldedNewlineStartedMoreIndented = moreIndented;
|
||||||
|
|
||||||
// for block scalars, we always start with a newline, so we should ignore it (not fold or keep)
|
// for block scalars, we always start with a newline, so we should ignore it (not fold or keep)
|
||||||
if(pastOpeningBreak) {
|
if(pastOpeningBreak) {
|
||||||
if(params.fold && !emptyLine && !nextEmptyLine && !moreIndented && !nextMoreIndented && INPUT.column() >= params.indent)
|
if(params.fold) {
|
||||||
scalar += " ";
|
if(!emptyLine && !nextEmptyLine && !moreIndented && !nextMoreIndented && INPUT.column() >= params.indent)
|
||||||
else
|
scalar += " ";
|
||||||
|
else if(nextEmptyLine)
|
||||||
|
foldedNewlineCount++;
|
||||||
|
else
|
||||||
|
scalar += "\n";
|
||||||
|
|
||||||
|
if(!nextEmptyLine && foldedNewlineCount > 0) {
|
||||||
|
if(foldedNewlineStartedMoreIndented || nextMoreIndented)
|
||||||
|
scalar += std::string("\n", foldedNewlineCount);
|
||||||
|
foldedNewlineCount = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
scalar += "\n";
|
scalar += "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emptyLine = nextEmptyLine;
|
emptyLine = nextEmptyLine;
|
||||||
|
Reference in New Issue
Block a user