Commit 84d7d946 authored by Steffen Michels's avatar Steffen Michels

Merge branch '69-json-and-utf-8' into 'master'

Don't let Text.GenJSON mess up UTF-8 strings

Closes #69

See merge request !262
parents f4ef279a 11e4d468
Pipeline #27673 passed with stage
in 3 minutes and 3 seconds
......@@ -24,7 +24,7 @@ from Data.GenEq import generic gEq
| JSONBool !Bool
| JSONInt !Int
| JSONReal !Real
| JSONString !String
| JSONString !String //* Only control characters and '"' will be escaped
| JSONArray ![JSONNode]
| JSONObject ![(String,JSONNode)]
| JSONRaw !String
......
......@@ -40,16 +40,13 @@ where
count i s n
| i < size s
#! c = s.[i]
| c == '"' || c == '/' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\\'
| c == '"' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\\'
= count (i + 1) s (n + 1) //We'll add a '\' to escape
| needsUniEscape c
| c < ' '
= count (i + 1) s (n + 5) //We'll replace the character by '\uXXXX'
= count(i + 1) s n
= n
needsUniEscape :: Char -> Bool
needsUniEscape c = c < ' ' || c >= '\x7f'
//Copy structure to a string
copyNode :: !Int !JSONNode !*{#Char} -> *(!Int, !*{#Char})
copyNode start (JSONNull) buffer = (start + 4, copyChars start 4 "null" buffer)
......@@ -119,11 +116,11 @@ copyAndEscapeChars soffset doffset num src dst
| num > 0
#! c = src.[soffset]
//Check for special characters
| c == '"' || c == '/' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\\'
| c == '"' || c == '\b' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\\'
#! dst & [doffset] = '\\'
#! dst & [doffset + 1] = charOf c
= copyAndEscapeChars (soffset + 1) (doffset + 2) (num - 1) src dst
| needsUniEscape c
| c < ' '
#! cint = toInt c
#! dst & [doffset] = '\\'
#! dst & [doffset + 1] = 'u'
......@@ -139,7 +136,6 @@ copyAndEscapeChars soffset doffset num src dst
= dst
where
charOf '"' = '"'
charOf '/' = '/'
charOf '\b' = 'b'
charOf '\f' = 'f'
charOf '\n' = 'n'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment