1 QuestHelper_File
["pattern.lua"] = "Development Version"
2 QuestHelper_Loadtime
["pattern.lua"] = GetTime()
4 -- The following junk is for building functions to parse strings for various locales.
6 local varindex
, varswap
= 0, {}
8 local function replacePattern(p
)
9 varindex
= varindex
+ 1
10 local b
, e
, i
= string.find(p
, "(%d-)%$")
13 -- String contains an index.
14 p
= string.sub(p
, 1, b
-1)..string.sub(p
, e
+1)
17 -- String doesn't contains an index, assume its index is the position we found it in.
23 if p
== "d" then return "(%d+)" end
24 if p
== "s" then return "(.-)" end
26 -- Only know about strings and integers. Other types are broken.
27 assert(false, "Unknown pattern: %"..p
)
30 -- Used to cache results, so we don't produce multiple functions for the same string.
31 local known_patterns
= {}
33 function QuestHelper
:convertPattern(pattern
)
34 local result
= known_patterns
[pattern
]
40 while(table.remove(varswap
)) do end
44 local pat
= string.format("^%s$", string.gsub(pattern
, "%%(.-[%%%a])", replacePattern
))
47 -- The string doesn't contain any variables.
50 local func
= "local function parse(input)\n"
54 if varswap
[i
] ~= i
then
61 -- All the arguments are in order, we can just return them.
62 func
= func
.. string.format("return select(3, string.find(input, %q))", pat
)
64 -- The order has been changed, use temporary variables.
66 func
= func
..(i
==1 and "local " or ", ")..("n"..i
)
69 func
= func
.. string.format(" = select(3, string.find(input, %q))\n", pat
)
72 func
= func
..(i
==1 and "return " or ", ")..(varswap
[i
] and ("n"..varswap
[i
]) or "nil")
76 func
= func
.. "\nend\nreturn parse\n"
78 result
= loadstring(func
)()
81 known_patterns
[pattern
] = result