Skip to content

Commit 65cd033

Browse files
committed
Half-assed support for escapes and Unicode.
1 parent ea5443f commit 65cd033

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

lib/json.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,15 @@ _json_char() {
338338
# are simple because they only require one character of
339339
# history. Unicode codepoint escapes require more. The
340340
# strategy there is to add states to the machine.
341+
#
342+
# TODO It'd be nice to decode all escape sequences, including
343+
# Unicode codepoints but that would definitely ruin the
344+
# line-oriented thing we've got goin' on.
341345
"string")
342346
case "$_J_PREV_C$_J_C" in
343347
"\\\""|"\\/"|"\\\\") _J_V="$_J_V$_J_C";;
344-
"\\b"|"\\f"|"\\n"|"\\r") ;; # TODO
345-
"\\u") ;; # TODO
348+
"\\b"|"\\f"|"\\n"|"\\r") _J_V="$_J_V\\\\$_J_C";;
349+
"\\u") _J_V="$_J_V\\\\$_J_C";;
346350
*"\"")
347351
_J_STATE="$_J_STATE_DEFAULT"
348352
echo "$_J_PATHNAME string $_J_V" >&$_J_FD;;

tests/blueprint.json.out

Lines changed: 23 additions & 23 deletions
Large diffs are not rendered by default.

tests/newline.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"\n"

tests/newline.json.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ string \n

tests/unicode.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"\u1234"

tests/unicode.json.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ string \u1234

0 commit comments

Comments
 (0)