bug fix - de-escape double backslashes in file paths of #line directives (#2462)

* bug fix - de-escape double backslashes in file paths of #line directives

From merged PR danmar/simplecpp#187.

* externals/simplecpp/simplecpp.cpp:
  - add static function REPLACEALL which replaces a string FROM to the
    string TO at every occurance in the input string.
  - simplecpp::TokenList::readfile: replace any double backslashes in any
    file path of a #line directive.

* externals/simplecpp/simplecpp.cpp: astyling
This commit is contained in:
jannick0 2019-12-29 14:01:19 +01:00 committed by Daniel Marjamäki
parent 75de485c4d
commit 1cef732e1b
1 changed files with 7 additions and 1 deletions

View File

@ -137,6 +137,12 @@ static bool isAlternativeUnaryOp(const simplecpp::Token *tok, const std::string
(tok->next && (tok->next->name || tok->next->number)));
}
static std::string replaceAll(std::string s, const std::string& from, const std::string& to)
{
for (size_t pos = s.find(from); pos != std::string::npos; pos = s.find(from, pos + to.size()))
s.replace(pos, from.size(), to);
return s;
}
const std::string simplecpp::Location::emptyFileName;
@ -498,7 +504,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
} else if (lastline == "# line %num%") {
lineDirective(location.fileIndex, std::atol(cback()->str().c_str()), &location);
} else if (lastline == "# %num% %str%" || lastline == "# line %num% %str%") {
lineDirective(fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U)),
lineDirective(fileIndex(replaceAll(cback()->str().substr(1U, cback()->str().size() - 2U),"\\\\","\\")),
std::atol(cback()->previous->str().c_str()), &location);
}
// #endfile