-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcskv.gs
More file actions
74 lines (71 loc) · 1.98 KB
/
cskv.gs
File metadata and controls
74 lines (71 loc) · 1.98 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
list cskv;
list cskv_keys;
list cskv_key_map;
%define CSKV_GET_INDEX(key) cskv_key_map[(key) in cskv_keys]
%define CSKV_GET(key) cskv[cskv_key_map[(key) in cskv_keys]]
proc cskv_unpack text {
delete cskv;
local token = "";
local i = 0;
until i > length($text) {
if $text[i] == "\\" {
if $text[i+1] in ",:\\" {
token &= $text[i+1];
i++;
} else {
token &= "\\";
}
} elif $text[i] == "," {
add token to cskv;
token = "";
} elif $text[i] == ":" {
add token to cskv_keys;
add 1+length(cskv) to cskv_key_map;
token = "";
} else {
token &= $text[i];
}
i++;
}
add token to cskv;
}
func cskv_pack() {
local result = "";
local i = 1;
until i > length(cskv_keys) {
result &= cskv_keys[i] & ":";
if (cskv_key_map[i+1] - cskv_key_map[i]) > 2 {
result &= cskv[cskv_key_map[i]] & ",";
local j = 1;
until j > cskv[cskv_key_map[i]] {
local element = cskv[cskv_key_map[i] + j];
local k = 1;
until k > length(element) {
if element[k] in "\\,:" {
result &= "\\";
}
result &= element[k];
k++;
}
j++;
if i < length(cskv_keys) or j < cskv[cskv_key_map[i]] {
result &= ",";
}
}
} else {
local j = 1;
until j > length(cskv[cskv_key_map[i]]) {
if cskv[cskv_key_map[i]][j] in "\\,:" {
result &= "\\";
}
result &= cskv[cskv_key_map[i]][j];
j++;
}
if i < length(cskv_keys) {
result &= ",";
}
}
i++;
}
return result;
}