diff options
Diffstat (limited to 'lualibs-lpeg.lua')
-rw-r--r-- | lualibs-lpeg.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index f060f3b..b107a8e 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -98,6 +98,15 @@ lpeg.splitat = splitat local cache = { } +function lpeg.split(separator,str) + local c = cache[separator] + if not c then + c = Ct(splitat(separator)) + cache[separator] = c + end + return match(c,str) +end + function string:split(separator) local c = cache[separator] if not c then @@ -107,8 +116,21 @@ function string:split(separator) return match(c,self) end +lpeg.splitters = cache + local cache = { } +function lpeg.checkedsplit(separator,str) + local c = cache[separator] + if not c then + separator = P(separator) + local other = C((1 - separator)^0) + c = Ct(separator^0 * other * (separator^1 * other)^0) + cache[separator] = c + end + return match(c,str) +end + function string:checkedsplit(separator) local c = cache[separator] if not c then |