Fixed folding bug (detecting indentation, example 8.2), and clipping/stripping empty strings (example 8.6)

This commit is contained in:
jbeder
2011-03-04 02:26:59 +00:00
parent cee0974abd
commit 1132c8df21

View File

@@ -143,7 +143,7 @@ namespace YAML
if(!nextEmptyLine && foldedNewlineCount > 0) {
scalar += std::string(foldedNewlineCount - 1, '\n');
if(foldedNewlineStartedMoreIndented || nextMoreIndented)
if(foldedNewlineStartedMoreIndented || nextMoreIndented | !foundNonEmptyLine)
scalar += "\n";
foldedNewlineCount = 0;
}
@@ -175,12 +175,23 @@ namespace YAML
scalar.erase(pos + 1);
}
if(params.chomp == STRIP || params.chomp == CLIP) {
std::size_t pos = scalar.find_last_not_of('\n');
if(params.chomp == CLIP && pos + 1 < scalar.size())
switch(params.chomp) {
case CLIP: {
const std::size_t pos = scalar.find_last_not_of('\n');
if(pos == std::string::npos)
scalar.erase();
else if(pos + 1 < scalar.size())
scalar.erase(pos + 2);
else if(params.chomp == STRIP && pos < scalar.size())
} break;
case STRIP: {
const std::size_t pos = scalar.find_last_not_of('\n');
if(pos == std::string::npos)
scalar.erase();
else if(pos < scalar.size())
scalar.erase(pos + 1);
} break;
default:
break;
}
return scalar;