|
|
@ -7,16 +7,24 @@
|
|
|
|
size_t fmt_jsonescape(char* dest,const char* src,size_t len) {
|
|
|
|
size_t fmt_jsonescape(char* dest,const char* src,size_t len) {
|
|
|
|
register const unsigned char* s=(const unsigned char*) src;
|
|
|
|
register const unsigned char* s=(const unsigned char*) src;
|
|
|
|
size_t written=0,i;
|
|
|
|
size_t written=0,i;
|
|
|
|
|
|
|
|
char c;
|
|
|
|
for (i=0; i<len; ++i) {
|
|
|
|
for (i=0; i<len; ++i) {
|
|
|
|
switch (s[i]) {
|
|
|
|
switch (s[i]) {
|
|
|
|
case '\\':
|
|
|
|
case '\\':
|
|
|
|
case '"':
|
|
|
|
case '"':
|
|
|
|
|
|
|
|
c=s[i];
|
|
|
|
|
|
|
|
escape:
|
|
|
|
if (dest) {
|
|
|
|
if (dest) {
|
|
|
|
dest[written]='\\';
|
|
|
|
dest[written]='\\';
|
|
|
|
dest[written+1]=s[i];
|
|
|
|
dest[written+1]=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
written+=2;
|
|
|
|
written+=2;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n': c='n'; goto escape;
|
|
|
|
|
|
|
|
case '\r': c='r'; goto escape;
|
|
|
|
|
|
|
|
case '\b': c='b'; goto escape;
|
|
|
|
|
|
|
|
case '\t': c='t'; goto escape;
|
|
|
|
|
|
|
|
case '\f': c='f'; goto escape;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
if (s[i]<' ') {
|
|
|
|
if (s[i]<' ') {
|
|
|
|
if (dest) {
|
|
|
|
if (dest) {
|
|
|
|