Fixed #5028 Fix parsing of C++11 raw string literals

This commit is contained in:
Malcolm Parsons 2015-08-12 13:11:55 +01:00
parent 6865724c4e
commit daf633ef78
2 changed files with 6 additions and 4 deletions

View File

@ -690,7 +690,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
else if (str.compare(i,2,"R\"")==0) {
std::string delim;
for (std::string::size_type i2 = i+2; i2 < str.length(); ++i2) {
if (i2 > 16 ||
if (i2 > 16 + i ||
std::isspace(str[i2]) ||
std::iscntrl(str[i2]) ||
str[i2] == ')' ||
@ -713,7 +713,9 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
} else if (std::iscntrl((unsigned char)str[p]) ||
std::isspace((unsigned char)str[p])) {
code << " ";
} else if (str[p] == '\"' || str[p] == '\'') {
} else if (str[p] == '\\') {
code << "\\\\";
} else if (str[p] == '\"') {
code << "\\" << (char)str[p];
} else {
code << (char)str[p];

View File

@ -316,12 +316,12 @@ private:
}
void readCode2() {
const char code[] = "R\"( \" /* abc */ \n)\";";
const char code[] = "R\"( \" \\ ' /* abc */ \n)\";";
Settings settings;
Preprocessor preprocessor(settings, this);
std::istringstream istr(code);
std::string codestr(preprocessor.read(istr,"test.c"));
ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n;", codestr);
ASSERT_EQUALS("\" \\\" \\\\ ' /* abc */ \\n\"\n;", codestr);
}
void readCode3() {