mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Fixed bug in parsing escaped newline (it was being clipped like a regular newline)
This commit is contained in:
@@ -23,6 +23,7 @@ namespace YAML
|
||||
bool emptyLine = false, moreIndented = false;
|
||||
int foldedNewlineCount = 0;
|
||||
bool foldedNewlineStartedMoreIndented = false;
|
||||
std::size_t lastEscapedChar = std::string::npos;
|
||||
std::string scalar;
|
||||
params.leadingSpaces = false;
|
||||
|
||||
@@ -52,6 +53,7 @@ namespace YAML
|
||||
// eat escape character and get out (but preserve trailing whitespace!)
|
||||
INPUT.get();
|
||||
lastNonWhitespaceChar = scalar.size();
|
||||
lastEscapedChar = scalar.size();
|
||||
escapedNewline = true;
|
||||
break;
|
||||
}
|
||||
@@ -60,6 +62,7 @@ namespace YAML
|
||||
if(INPUT.peek() == params.escape) {
|
||||
scalar += Exp::Escape(INPUT);
|
||||
lastNonWhitespaceChar = scalar.size();
|
||||
lastEscapedChar = scalar.size();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -171,20 +174,32 @@ namespace YAML
|
||||
// post-processing
|
||||
if(params.trimTrailingSpaces) {
|
||||
std::size_t pos = scalar.find_last_not_of(' ');
|
||||
if(lastEscapedChar != std::string::npos) {
|
||||
if(pos < lastEscapedChar || pos == std::string::npos)
|
||||
pos = lastEscapedChar;
|
||||
}
|
||||
if(pos < scalar.size())
|
||||
scalar.erase(pos + 1);
|
||||
}
|
||||
|
||||
switch(params.chomp) {
|
||||
case CLIP: {
|
||||
const std::size_t pos = scalar.find_last_not_of('\n');
|
||||
std::size_t pos = scalar.find_last_not_of('\n');
|
||||
if(lastEscapedChar != std::string::npos) {
|
||||
if(pos < lastEscapedChar || pos == std::string::npos)
|
||||
pos = lastEscapedChar;
|
||||
}
|
||||
if(pos == std::string::npos)
|
||||
scalar.erase();
|
||||
else if(pos + 1 < scalar.size())
|
||||
scalar.erase(pos + 2);
|
||||
} break;
|
||||
case STRIP: {
|
||||
const std::size_t pos = scalar.find_last_not_of('\n');
|
||||
std::size_t pos = scalar.find_last_not_of('\n');
|
||||
if(lastEscapedChar != std::string::npos) {
|
||||
if(pos < lastEscapedChar || pos == std::string::npos)
|
||||
pos = lastEscapedChar;
|
||||
}
|
||||
if(pos == std::string::npos)
|
||||
scalar.erase();
|
||||
else if(pos < scalar.size())
|
||||
|
Reference in New Issue
Block a user