Fix to escape VERILATOR_ROOT file paths (#3764) (#3765)

This commit is contained in:
Jiacheng Qian
2022-11-20 10:25:41 -05:00
committed by GitHub
parent 278d532368
commit 47253450a4
6 changed files with 40 additions and 30 deletions
+13
View File
@@ -116,6 +116,19 @@ string VString::quoteStringLiteralForShell(const string& str) {
return result;
}
string VString::escapeStringForPath(const string &str) {
if (str.find(R"(\\)") != string::npos) return str; // if it has been escaped already, don't do it again
if (str.find('/') != string::npos) return str; // can be replaced by `__MINGW32__` or `_WIN32`
string result;
const char space = ' '; // escape space like this `Program Files`
const char escape = '\\';
for (const char c: str) {
if (c == space || c == escape) result.push_back(escape);
result.push_back(c);
}
return result;
}
string VString::spaceUnprintable(const string& str) {
string out;
for (const char c : str) {