-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_helpers.lua
73 lines (66 loc) · 1.38 KB
/
parse_helpers.lua
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
function string:split (sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
function table_size(table)
local count = 0
for _ in pairs(table) do count = count + 1 end
return count
end
function variable_to_table(var, sep)
if type(var) == 'string' then
return var:split(sep)
elseif type(var) == 'table' then
return var
else
return nil
end
end
function string:toboolean()
--- constants
local TRUE = {
['1'] = true,
['t'] = true,
['T'] = true,
['true'] = true,
['TRUE'] = true,
['True'] = true,
}
local FALSE = {
['0'] = false,
['f'] = false,
['F'] = false,
['false'] = false,
['FALSE'] = false,
['False'] = false,
}
if TRUE[self] == true then
return true
elseif FALSE[self] == false then
return false
else
return nil
end
end
function variable_to_boolean(var)
if type(var) == 'string' then
return var:toboolean()
elseif type(var) == 'boolean' then
return var
else
return nil
end
end
function record_prefix_all(record, prefix)
local prefixed_record = {}
for k,v in pairs(record) do
if k:match("^%a") then
prefixed_record[prefix..k] = v
else
prefixed_record[k] = v
end
end
return prefixed_record
end