1
0
Fork 0
mirror of https://gitlab.com/niansa/anyproc.git synced 2025-03-06 20:49:24 +01:00

Another unescaping fix

This commit is contained in:
niansa 2023-04-17 00:18:58 +02:00
parent 5c66ef1c18
commit 0a2dee3a2e

View file

@ -26,15 +26,16 @@ public:
return fres;
}
static inline const std::string unescape(std::string_view str) {
unsigned backTruncateCount = 0;
while (*(str.end()-backTruncateCount-1) == ' ') backTruncateCount++;
const char quotes = str[0];
if (quotes != '"' && quotes != '\'') {
return std::string(str);
}
std::string fres;
for (const char c : std::string_view{str.data()+1, str.size()-2}) {
for (const char c : std::string_view{str.data()+1, str.size()-2-backTruncateCount}) {
if (c != '\\') fres.push_back(c);
}
while (fres.back() == quotes) fres.pop_back();
return fres;
}