mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix a utf8 bug
This commit is contained in:
parent
e733d7cd23
commit
a9a4ef6dda
@ -98,15 +98,26 @@ void c11_sbuf__write_quoted(c11_sbuf* self, c11_sv sv, char quote) {
|
|||||||
case '\r': c11_sbuf__write_cstrn(self, "\\r", 2); break;
|
case '\r': c11_sbuf__write_cstrn(self, "\\r", 2); break;
|
||||||
case '\t': c11_sbuf__write_cstrn(self, "\\t", 2); break;
|
case '\t': c11_sbuf__write_cstrn(self, "\\t", 2); break;
|
||||||
case '\b': c11_sbuf__write_cstrn(self, "\\b", 2); break;
|
case '\b': c11_sbuf__write_cstrn(self, "\\b", 2); break;
|
||||||
default:
|
default: {
|
||||||
if(!isprint(c)) {
|
int u8bytes = c11__u8_header(c, true);
|
||||||
unsigned char uc = (unsigned char)c;
|
if(u8bytes <= 1) {
|
||||||
c11_sbuf__write_cstrn(self, "\\x", 2);
|
// not a valid utf8 char, or ascii
|
||||||
c11_sbuf__write_char(self, PK_HEX_TABLE[uc >> 4]);
|
if(!isprint(c)) {
|
||||||
c11_sbuf__write_char(self, PK_HEX_TABLE[uc & 0xf]);
|
unsigned char uc = (unsigned char)c;
|
||||||
|
c11_sbuf__write_cstrn(self, "\\x", 2);
|
||||||
|
c11_sbuf__write_char(self, PK_HEX_TABLE[uc >> 4]);
|
||||||
|
c11_sbuf__write_char(self, PK_HEX_TABLE[uc & 0xf]);
|
||||||
|
} else {
|
||||||
|
c11_sbuf__write_char(self, c);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
c11_sbuf__write_char(self, c);
|
for(int j = 0; j < u8bytes; j++) {
|
||||||
|
c11_sbuf__write_char(self, sv.data[i + j]);
|
||||||
|
}
|
||||||
|
i += u8bytes - 1;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c11_sbuf__write_char(self, quote);
|
c11_sbuf__write_char(self, quote);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user