Merge pull request #4567 from kivikakk/cxxrtl-escape-trailing

cxxrtl: use octal encoding of non-printables.
This commit is contained in:
KrystalDelusion
2025-03-14 16:52:07 +13:00
committed by GitHub
2 changed files with 6 additions and 5 deletions
+1 -1
View File
@@ -616,7 +616,7 @@ std::string escape_c_string(const std::string &input)
output.push_back('\\'); output.push_back('\\');
output.push_back(c); output.push_back(c);
} else { } else {
char l = c & 0x3, m = (c >> 3) & 0x3, h = (c >> 6) & 0x3; char l = c & 0x7, m = (c >> 3) & 0x7, h = (c >> 6) & 0x3;
output.append("\\"); output.append("\\");
output.push_back('0' + h); output.push_back('0' + h);
output.push_back('0' + m); output.push_back('0' + m);
+5 -4
View File
@@ -634,10 +634,11 @@ std::string escape_cxx_string(const std::string &input)
output.push_back('\\'); output.push_back('\\');
output.push_back(c); output.push_back(c);
} else { } else {
char l = c & 0xf, h = (c >> 4) & 0xf; char l = c & 0x7, m = (c >> 3) & 0x7, h = (c >> 6) & 0x3;
output.append("\\x"); output.push_back('\\');
output.push_back((h < 10 ? '0' + h : 'a' + h - 10)); output.push_back('0' + h);
output.push_back((l < 10 ? '0' + l : 'a' + l - 10)); output.push_back('0' + m);
output.push_back('0' + l);
} }
} }
output.push_back('"'); output.push_back('"');