-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstring.lua
More file actions
28 lines (23 loc) · 616 Bytes
/
string.lua
File metadata and controls
28 lines (23 loc) · 616 Bytes
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
local module = {}
playdate.string = module
function module.UUID(length)
local str = ""
for i = 1, length do
str = str..string.char(math.random(65, 90))
end
return str
end
function module.getTextSize(str)
return playdate.graphics.getTextSize(str)
end
-- trim7() from http://lua-users.org/wiki/StringTrim
local match = string.match
function module.trimWhitespace(str)
return match(str, '^()%s*$') and '' or match(str, '^%s*(.*%S)')
end
function module.trimLeadingWhitespace(str)
return match(str, '^%s*(.+)')
end
function module.trimTrailingWhitespace(str)
return match(str, '(.-)%s*$')
end