Skip to content

Commit 54b6f76

Browse files
committed
Fix escape of special char
1 parent 77f486e commit 54b6f76

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ std::string Converter::GetEscapedCharLiteral(char character) const {
17281728
return "\\0";
17291729
}
17301730
auto uc = static_cast<unsigned char>(character);
1731-
if (uc < 0x20 || uc == 0x7F) {
1731+
if (uc < 0x20 || uc >= 0x7F) {
17321732
return std::format("\\x{:02x}", uc);
17331733
}
17341734
return std::string(1, character);

tests/unit/string_escape.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include <string.h>
33

44
int main() {
5-
const char *special = "\a\b\t\n\v\f\r !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~";
5+
const char *special = "\a\b\t\n\v\f\r !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~\xff";
66
static const char expected[] = {
77
7, 8, 9, 10, 11, 12, 13, 32, 33, 34, 35, 36, 37, 38,
88
39, 40, 41, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 62,
9-
63, 64, 91, 92, 93, 94, 95, 96, 123, 124, 125, 126,
9+
63, 64, 91, 92, 93, 94, 95, 96, 123, 124, 125, 126, 255
1010
};
1111
for (int i = 0; i < (int)(sizeof(expected) / sizeof(expected[0])); i++) {
1212
assert(special[i] == expected[i]);

0 commit comments

Comments
 (0)