forked from Unisay/purescript-lua-strings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.lua
More file actions
32 lines (32 loc) · 1.04 KB
/
Common.lua
File metadata and controls
32 lines (32 loc) · 1.04 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
return {
_localeCompare = (function(lt)
return function(eq)
return function(gt)
return function(s1) return function(s2) return (s1 < s2) and lt or (s2 < s1) and gt or eq end end
end
end
end),
replace = (function(pattern)
return function(replacement) return function(string) return string:gsub(pattern, replacement, 1) end end
end),
replaceAll = (function(pattern)
return function(replacement) return function(string) return string:gsub(pattern, replacement) end end
end),
split = (function(sep)
return function(s)
local t = {}
local pattern
if string.len(s) == 0 then
pattern = "(.)"
else
pattern = "([^" .. sep .. "]+)"
end
for str in s:gmatch(pattern) do table.insert(t, str) end
return t
end
end),
toLower = (function(s) return s:lower() end),
toUpper = (function(s) return s:upper() end),
trim = (function(s) return s:match("^%s*(.-)%s*$") end),
joinWith = (function(sep) return function(xs) return table.concat(xs, sep) end end)
}