Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
ffworker
Commits
cb71f573
Commit
cb71f573
authored
Nov 01, 2017
by
Julian Rother
Browse files
Added json string escape function
parent
1e06a2b5
Changes
2
Show whitespace changes
Inline
Side-by-side
util.h
View file @
cb71f573
...
...
@@ -24,4 +24,4 @@ char *jenter(char *s);
char
*
jnext
(
char
*
s
);
char
*
jvalue
(
char
*
s
);
char
*
jlookup
(
char
*
s
,
char
*
key
);
char
*
jescape
(
char
*
s
);
util/json.c
View file @
cb71f573
...
...
@@ -5,6 +5,9 @@
#include "../util.h"
static
char
hex
[]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
static
char
*
skip_ws
(
char
*
s
)
{
for
(;
*
s
==
' '
||
*
s
==
'\t'
||
*
s
==
'\n'
||
*
s
==
'\r'
;
s
++
);
...
...
@@ -210,3 +213,41 @@ char *jlookup(char *s, char *key)
return
jvalue
(
s
);
return
0
;
}
char
*
jescape
(
char
*
s
)
{
int
i
;
static
__thread
char
buf
[
JSTR_SIZE
];
for
(
i
=
0
;
*
s
&&
i
+
7
<
sizeof
(
buf
);
s
++
)
switch
(
*
s
)
{
case
'"'
:
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
'"'
;
break
;
case
'\\'
:
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
'\\'
;
break
;
case
'\b'
:
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
'b'
;
break
;
case
'\f'
:
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
'f'
;
break
;
case
'\n'
:
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
'n'
;
break
;
case
'\r'
:
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
'r'
;
break
;
case
'\t'
:
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
't'
;
break
;
default:
if
(
*
s
<=
0x1f
)
{
buf
[
i
++
]
=
'\\'
;
buf
[
i
++
]
=
'u'
;
buf
[
i
++
]
=
'0'
;
buf
[
i
++
]
=
'0'
;
buf
[
i
++
]
=
hex
[
*
s
>>
4
];
buf
[
i
++
]
=
hex
[
*
s
&
0xf
];
}
else
buf
[
i
++
]
=
*
s
;
}
buf
[
i
]
=
0
;
return
buf
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment