js_tools.anubis
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Created by PyramIDE.
* User: フランスのトトロ
* Date: 18/04/2015
* Time: 23:21
* © Calexium
*/
read tools/basis.anubis
define List(Word8)
make_js_string
(
List(Word8) current,
List(Word8) so_far
)
=
if current is
{
[ ] then reverse(so_far),
[h . t] then
make_js_string(t,
if h = '\'' then [ h, '\\' . so_far] //single quote
else if h = '\"' then [ h, '\\' . so_far]
else if h = '\r' then ['r', '\\' . so_far] //CR
else if h = '\n' then ['n', '\\' . so_far] //LF
else if h = '\t' then ['t', '\\' . so_far] //tab
else if h = 0x08 then ['b', '\\' . so_far] //Backspace
else
[h . so_far]
)
}.
/**
* Convert a string into certified javascript string (I hope)
*/
public define String
make_js_string
(
String str
)
=
implode(make_js_string(explode(str), [])).
public define String
to_js_string
(
String str
)
=
"'" + make_js_string(str) + "'".
public define String
format_js_function_call
(
String name,
List(String) args
) =
name + "(" + concat(args, ",") + ");".