-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTEST.MV.TO.JS
58 lines (51 loc) · 1.51 KB
/
TEST.MV.TO.JS
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
** Test Case **
DYN.ARRAY = ''
DYN.ARRAY<1> = 'SUE]]DAVE]'
DYN.ARRAY<2> = '255\122]]-45\RED\99'
DYN.ARRAY<3> = '1357]Green, "St"]Paris]FR'
DYN.ARRAY<5> = 'OPEN'
CONVERT "]" TO @VM IN DYN.ARRAY
CONVERT "\" TO @SVM IN DYN.ARRAY
** Escape quotes in string values **
DYN.ARRAY = CHANGE(DYN.ARRAY,'"', '\"')
GOSUB CONVERT.TO.JS
CRT JS.ARRAY
STOP
** End test case **
CONVERT.TO.JS: *
FORCE.THREE.DIMENSIONS = 1
MAX.ATTRIBUTES = DCOUNT(DYN.ARRAY, @AM)
JS.ARRAY = '['
FOR A.POS = 1 TO MAX.ATTRIBUTES
IF A.POS > 1 THEN JS.ARRAY := ', '
A.VALUE = DYN.ARRAY<A.POS>
MAX.VALUES = DCOUNT(A.VALUE, @VM)
IF MAX.VALUES = 0 THEN MAX.VALUES = 1
IF MAX.VALUES > 1 THEN JS.ARRAY := '['
FOR V.POS = 1 TO MAX.VALUES
V.VALUE = A.VALUE<1,V.POS>
IF V.POS > 1 THEN JS.ARRAY := ', '
MAX.SUBVALUES = DCOUNT(V.VALUE, @SVM)
IF MAX.SUBVALUES = 0 THEN MAX.SUBVALUES = 1
IF MAX.SUBVALUES > 1 OR FORCE.THREE.DIMENSIONS THEN
IF MAX.VALUES = 1 THEN JS.ARRAY := '['
JS.ARRAY := '['
END
FOR S.POS = 1 TO MAX.SUBVALUES
IF S.POS > 1 THEN JS.ARRAY := ', '
S.VALUE = V.VALUE<1,1,S.POS>
IF S.VALUE # '' AND NUM(S.VALUE) THEN
JS.ARRAY := S.VALUE
END ELSE
JS.ARRAY := '"':S.VALUE:'"'
END
NEXT S.POS
IF MAX.SUBVALUES > 1 OR FORCE.THREE.DIMENSIONS THEN
JS.ARRAY := ']'
IF MAX.VALUES = 1 THEN JS.ARRAY := ']'
END
NEXT V.POS
IF MAX.VALUES > 1 THEN JS.ARRAY := ']'
NEXT A.POS
JS.ARRAY := ']'
RETURN