From 1cef732e1b1b4199c7490b3bff65e9e77181e29e Mon Sep 17 00:00:00 2001 From: jannick0 Date: Sun, 29 Dec 2019 14:01:19 +0100 Subject: [PATCH] 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 --- externals/simplecpp/simplecpp.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 2c38cd67b..6de395055 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -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