-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparse.lua
34 lines (26 loc) · 874 Bytes
/
parse.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
-- Code adapted from TomTom
local wrongseparator = "(%d)" .. (tonumber("1.1") and "," or ".") .. "(%d)"
local rightseparator = "%1" .. (tonumber("1.1") and "." or ",") .. "%2"
function SlashPin:ParseCmd(str)
local tokens = {}
str = str:gsub("(%d)[%.,] (%d)", "%1 %2"):gsub(wrongseparator, rightseparator)
for token in str:gmatch("%S+") do
table.insert(tokens, token)
end
return tokens
end
function SlashPin:ParseTokens(tokens)
local zoneEnd
for i = 1, #tokens do
local token = tokens[i]
if tonumber(token) then
-- We've encountered a number, so the zone name must have ended at the prior token
zoneEnd = i - 1
break
end
end
if not zoneEnd then
return nil
end
return table.concat(tokens, " ", 1, zoneEnd), select(zoneEnd + 1, unpack(tokens))
end