From ed0275bf230dfa5ef7d8e48d81948d4a52b193c7 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 6 Jul 2014 23:21:18 +0200 Subject: sync with Context as of 2014-07-06 --- lualibs-lpeg.lua | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index c203d80..79e75a7 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -897,17 +897,35 @@ end function lpeg.utfchartabletopattern(list) -- goes to util-lpg local tree = { } local hash = { } - for i=1,#list do - local t = tree - for c in gmatch(list[i],".") do - local tc = t[c] - if not tc then - tc = { } - t[c] = tc + local n = #list + if n == 0 then + -- we could always use this branch + for s in next, list do + local t = tree + for c in gmatch(s,".") do + local tc = t[c] + if not tc then + tc = { } + t[c] = tc + end + t = tc + end + hash[t] = s + end + else + for i=1,n do + local t = tree + local s = list[i] + for c in gmatch(s,".") do + local tc = t[c] + if not tc then + tc = { } + t[c] = tc + end + t = tc end - t = tc + hash[t] = s end - hash[t] = list[i] end return make(tree,hash) end -- cgit v1.2.3