Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
50
Task/JSON/Lingo/json-2.lingo
Normal file
50
Task/JSON/Lingo/json-2.lingo
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
----------------------------------------
|
||||
-- JSON encoder
|
||||
-- Supported Lingo data types: VOID, integer, float, string, symbol, list, propList
|
||||
-- @param {any} o
|
||||
-- @return {string}
|
||||
----------------------------------------
|
||||
on json_encode (o)
|
||||
case ilk(o) of
|
||||
#void:
|
||||
return "null"
|
||||
#integer, #float:
|
||||
return string(o)
|
||||
#string:
|
||||
return QUOTE & _json_escape_string(o) & QUOTE
|
||||
#list:
|
||||
res = []
|
||||
repeat with v in o
|
||||
res.add(json_encode(v))
|
||||
end repeat
|
||||
return "[" & _cimplode(res) & "]"
|
||||
#propList:
|
||||
res = []
|
||||
cnt = count(o)
|
||||
repeat with i = 1 to cnt
|
||||
p = o.getPropAt(i)
|
||||
v = o[i]
|
||||
res.add( json_encode(p)&":"&json_encode(v) )
|
||||
end repeat
|
||||
return "{" & _cimplode(res) & "}"
|
||||
#symbol:
|
||||
-- optional support of special Lingo data type 'symbol' unknown to JavaScript
|
||||
return QUOTE &"__sym__"&_json_escape_string(string(o)) & QUOTE
|
||||
otherwise:
|
||||
put "ERROR: unsupported data type"
|
||||
end case
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- Implodes list into comma-separated string
|
||||
-- @param {list} l
|
||||
-- @return {string}
|
||||
----------------------------------------
|
||||
on _cimplode (l)
|
||||
str=""
|
||||
repeat with i=1 to l.count
|
||||
put l[i]&"," after str
|
||||
end repeat
|
||||
delete the last char of str
|
||||
return str
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue