diff --git a/src/exp.cpp b/src/exp.cpp index b5cb815..7f4256f 100644 --- a/src/exp.cpp +++ b/src/exp.cpp @@ -83,7 +83,7 @@ namespace YAML // now do the slash (we're not gonna check if it's a slash - you better pass one!) switch(ch) { - case '0': return std::string("\x00", 1); + case '0': return std::string(1, '\x00'); case 'a': return "\x07"; case 'b': return "\x08"; case 't': diff --git a/src/scanscalar.cpp b/src/scanscalar.cpp index 5a38943..3432653 100644 --- a/src/scanscalar.cpp +++ b/src/scanscalar.cpp @@ -110,7 +110,7 @@ namespace YAML // was this an empty line? bool nextEmptyLine = Exp::Break.Matches(INPUT); - bool nextMoreIndented = (INPUT.peek() == ' '); + bool nextMoreIndented = Exp::Blank.Matches(INPUT); if(params.fold && foldedNewlineCount == 0 && nextEmptyLine) foldedNewlineStartedMoreIndented = moreIndented; @@ -125,8 +125,9 @@ namespace YAML scalar += "\n"; if(!nextEmptyLine && foldedNewlineCount > 0) { + scalar += std::string(foldedNewlineCount - 1, '\n'); if(foldedNewlineStartedMoreIndented || nextMoreIndented) - scalar += std::string("\n", foldedNewlineCount); + scalar += "\n"; foldedNewlineCount = 0; } } else { diff --git a/yaml-reader/spectests.cpp b/yaml-reader/spectests.cpp index 1093a71..cd176a7 100644 --- a/yaml-reader/spectests.cpp +++ b/yaml-reader/spectests.cpp @@ -952,6 +952,65 @@ namespace Test { YAML_ASSERT(doc["Chomping"] == "Clipped empty lines\n"); return true; } + + // 6.6 + TEST LineFolding() + { + std::string input = + ">-\n" + " trimmed\n" + " \n" + " \n" + "\n" + " as\n" + " space"; + std::stringstream stream(input); + YAML::Parser parser(stream); + YAML::Node doc; + parser.GetNextDocument(doc); + + YAML_ASSERT(doc == "trimmed\n\n\nas space"); + return true; + } + + // 6.7 + TEST BlockFolding() + { + std::string input = + ">\n" + " foo \n" + " \n" + " \t bar\n" + "\n" + " baz\n"; + std::stringstream stream(input); + YAML::Parser parser(stream); + YAML::Node doc; + parser.GetNextDocument(doc); + + YAML_ASSERT(doc == "foo \n\n\t bar\n\nbaz\n"); + return true; + } + + // 6.8 + TEST FlowFolding() + { + std::string input = + "\"\n" + " foo \n" + " \n" + " \t bar\n" + "\n" + " baz\n" + "\""; + std::stringstream stream(input); + YAML::Parser parser(stream); + YAML::Node doc; + parser.GetNextDocument(doc); + + YAML_ASSERT(doc == " foo\nbar\nbaz "); + return true; + } } bool RunSpecTests() @@ -995,6 +1054,9 @@ namespace Test { RunSpecTest(&Spec::SeparationSpaces, "6.3", "Separation Spaces", passed, total); RunSpecTest(&Spec::LinePrefixes, "6.4", "Line Prefixes", passed, total); RunSpecTest(&Spec::EmptyLines, "6.5", "Empty Lines", passed, total); + RunSpecTest(&Spec::LineFolding, "6.6", "Line Folding", passed, total); + RunSpecTest(&Spec::BlockFolding, "6.7", "Block Folding", passed, total); + RunSpecTest(&Spec::FlowFolding, "6.8", "Flow Folding", passed, total); std::cout << "Spec tests: " << passed << "/" << total << " passed\n"; return passed == total;