1
2
3
4
5
6
7
..
32
33
34
35
36
37
38
39
|
return {
capitalize = function(str)
return string.upper(string.sub(str, 1,1)) .. string.sub(str, 2)
end;
rand = function(min,max)
if not min then min = 16 end
................................................................................
str = string.sub(str, 2)
end
if string.sub(str, #str,#str) == ' ' then
str = string.sub(str, 1, #str - 1)
end
return str
end;
}
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
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
75
76
|
local sanitable = {
['\xfe'] = '\xf0';
['\1'] = '\xf1';
['\2'] = '\xf2';
['\3'] = '\xf3';
['\xf0'] = '\xfe';
['\xf1'] = '\1';
['\xf2'] = '\2';
['\xf3'] = '\3';
}
return {
capitalize = function(str)
return string.upper(string.sub(str, 1,1)) .. string.sub(str, 2)
end;
rand = function(min,max)
if not min then min = 16 end
................................................................................
str = string.sub(str, 2)
end
if string.sub(str, #str,#str) == ' ' then
str = string.sub(str, 1, #str - 1)
end
return str
end;
meta_armor = function(str,mark_struct)
-- binary values stored in metadata need to be sanitized so
-- they don't contain values that will disrupt parsing of the
-- KV store, as minetest (stupidly) uses in-band signalling
local sanitized = string.gsub(str, '[\xfe\1\2\3]', function(char)
return '\xfe' .. sanitable[char]
end)
if sanitized ~= str and mark_struct then
-- use different type code to mark struct headers for
-- back-compat
return string.gsub(sanitized,'^\xfe\xf0\x99','\xfe\x98')
else return sanitized end
end;
meta_dearmor = function(str,cond)
local dearmor = function(s)
return string.gsub(s, '\xfe([\xf0\xf1\xf2\xf3])', function(char)
return sanitable[char]
end)
end
if cond then
if string.sub(str,1,2) == '\xfe\x98' then
return dearmor(string.gsub(str,'^\xfe\x98','\xfe\xf0\x99'))
else return str end
else return dearmor(str) end
end;
}
|