Merge pull request #641 from pepsiman/rawstringliteral

Fixed #5028  Fix parsing of C++11 raw string literals
This commit is contained in:
orbitcowboy 2015-08-12 15:01:00 +02:00
commit b927b77fc4
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) { else if (str.compare(i,2,"R\"")==0) {
std::string delim; std::string delim;
for (std::string::size_type i2 = i+2; i2 < str.length(); ++i2) { for (std::string::size_type i2 = i+2; i2 < str.length(); ++i2) {
if (i2 > 16 || if (i2 > 16 + i ||
std::isspace(str[i2]) || std::isspace(str[i2]) ||
std::iscntrl(str[i2]) || std::iscntrl(str[i2]) ||
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]) || } else if (std::iscntrl((unsigned char)str[p]) ||
std::isspace((unsigned char)str[p])) { std::isspace((unsigned char)str[p])) {
code << " "; code << " ";
} else if (str[p] == '\"' || str[p] == '\'') { } else if (str[p] == '\\') {
code << "\\\\";
} else if (str[p] == '\"') {
code << "\\" << (char)str[p]; code << "\\" << (char)str[p];
} else { } else {
code << (char)str[p]; code << (char)str[p];

View File

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