diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/sort-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/sort-ini.lua | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/Master/texmf-dist/tex/context/base/sort-ini.lua b/Master/texmf-dist/tex/context/base/sort-ini.lua index 479d1c48957..9ac020166a8 100644 --- a/Master/texmf-dist/tex/context/base/sort-ini.lua +++ b/Master/texmf-dist/tex/context/base/sort-ini.lua @@ -82,7 +82,7 @@ local v_first = variables.first local v_last = variables.last local validmethods = table.tohash { - -- "ch", -- raw character + "ch", -- raw character (for tracing) "mm", -- minus mapping "zm", -- zero mapping "pm", -- plus mapping @@ -120,7 +120,7 @@ local sorters = sorters local constants = sorters.constants local data, language, method, digits -local replacements, m_mappings, z_mappings, p_mappings, entries, orders, lower, upper, method, sequence +local replacements, m_mappings, z_mappings, p_mappings, entries, orders, lower, upper, method, sequence, usedinsequence local thefirstofsplit local mte = { -- todo: assign to t @@ -334,6 +334,9 @@ local function setlanguage(l,m,d,u) end end data.sequence = sequence + usedinsequence = table.tohash(sequence) + data.usedinsequence = usedinsequence +-- usedinsequence.ch = true -- better just store the string if trace_tests then report_sorters("using sort sequence: % t",sequence) end @@ -372,7 +375,9 @@ local function basicsort(sort_a,sort_b) return 0 end -function comparers.basic(a,b) -- trace ea and eb +-- todo: compile compare function + +local function basic(a,b) -- trace ea and eb local ea, eb = a.split, b.split local na, nb = #ea, #eb if na == 0 and nb == 0 then @@ -432,6 +437,12 @@ function comparers.basic(a,b) -- trace ea and eb end end +comparers.basic = basic + +function sorters.basicsorter(a,b) + return basic(a,b) == -1 +end + local function numify(s) s = digitsoffset + tonumber(s) -- alternatively we can create range if s > digitsmaximum then @@ -446,7 +457,7 @@ function sorters.strip(str) -- todo: only letters and such str = gsub(str,"\\[\"\'~^`]*","") -- \"e -- hm, too greedy str = gsub(str,"\\%S*","") -- the rest str = gsub(str,"%s","\001") -- can be option - str = gsub(str,"[%s%[%](){}%$\"\']*","") + str = gsub(str,"[%s%[%](){}%$\"\']*","") -- %s already done if digits == v_numbers then str = gsub(str,"(%d+)",numify) -- sort numbers properly end @@ -477,7 +488,7 @@ sorters.firstofsplit = firstofsplit -- for the moment we use an inefficient bunch of tables but once -- we know what combinations make sense we can optimize this -function splitters.utf(str) -- we could append m and u but this is cleaner, s is for tracing +function splitters.utf(str,checked) -- we could append m and u but this is cleaner, s is for tracing if #replacements > 0 then -- todo make an lpeg for this for k=1,#replacements do @@ -580,18 +591,31 @@ function splitters.utf(str) -- we could append m and u but this is cleaner, s is -- p_mapping = { p_mappings[fs][1] } -- end -- end - local t = { - ch = char, - uc = byte, - mc = m_case, - zc = z_case, - pc = p_case, - mm = m_mapping, - zm = z_mapping, - pm = p_mapping, - } - return t + if checked then + return { + ch = trace_tests and char or nil, -- not in sequence + uc = usedinsequence.uc and byte or nil, + mc = usedinsequence.mc and m_case or nil, + zc = usedinsequence.zc and z_case or nil, + pc = usedinsequence.pc and p_case or nil, + mm = usedinsequence.mm and m_mapping or nil, + zm = usedinsequence.zm and z_mapping or nil, + pm = usedinsequence.pm and p_mapping or nil, + } + else + return { + ch = char, + uc = byte, + mc = m_case, + zc = z_case, + pc = p_case, + mm = m_mapping, + zm = z_mapping, + pm = p_mapping, + } + end + end local function packch(entry) |