forked from jsb/Gatherer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
string.lua
40 lines (33 loc) · 927 Bytes
/
string.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
-- String related routines
--
function Gatherer_split(str, sep)
-- type: (Text, Text) -> List[Text]
-- This *wonderful* language has no split function.
-- And this *wonderful* lua implementation has neither match nor gmatch.
local sep, fields = sep or ",", {}
local pattern = string.format("([^%s]+)", sep)
gsub(str, pattern, function(c) tinsert(fields, c) end)
return fields
end
function Gatherer_table_to_string(table)
-- type: (dict) -> Text
local result_str = ''
if not table then
return result_str
end
for k, v in table do
result_str = result_str..tostring(k)..': '..tostring(v)..', '
end
return result_str
end
local function hexColor(color)
-- type: (Color) -> HexColor
local hexColor = {};
for _, component in color do
tinsert(hexColor, format('%x', component))
end
return table.concat(hexColor)
end
function Gatherer_coloredText(str, color)
return '|cff'..hexColor(color)..str..'|r'
end