Skip to content

Add support for combining characters #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions json.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ end

on encodeString(value)
set rv to ""
repeat with ch in value
if id of ch = 34
set codepoints to id of value

if (class of codepoints) is not list
set codepoints to {codepoints}
end

repeat with codepoint in codepoints
set codepoint to codepoint as integer
if codepoint = 34
set quoted_ch to "\\\""
else if id of ch = 92 then
else if codepoint = 92 then
set quoted_ch to "\\\\"
else if id of ch >= 32 and id of ch < 127
set quoted_ch to ch
else if codepoint >= 32 and codepoint < 127
set quoted_ch to character id codepoint
else
set quoted_ch to "\\u" & hex4(id of ch)
set quoted_ch to "\\u" & hex4(codepoint)
end
set rv to rv & quoted_ch
end
Expand Down
1 change: 1 addition & 0 deletions tests.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ assert_eq(json's encode("foo"), "\"foo\"")
assert_eq(json's encode(""), "\"\"")
assert_eq(json's encode("\n"), "\"\\u000a\"")
assert_eq(json's encode("ș"), "\"\\u0219\"")
assert_eq(json's encode("u" & "̈"), "\"u\\u0308\"")
assert_eq(json's encode("\"bar\""), "\"\\\"bar\\\"\"")
assert_eq(json's encode("\\"), "\"\\\\\"")

Expand Down