• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 14390735465

10 Apr 2025 09:30PM UTC coverage: 34.559% (-31.7%) from 66.23%
14390735465

push

github

alerque
Merge tag 'v0.15.12' into develop

4 of 4 new or added lines in 3 files covered. (100.0%)

4064 existing lines in 73 files now uncovered.

6918 of 20018 relevant lines covered (34.56%)

2597.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.05
/core/utilities/sorting.lua
1
--- Table sorting with language-dependent collation.
2
-- @module SU.sorting
3
--
4

5
local icu = require("justenoughicu")
196✔
6

7
local collatedSort = {
196✔
8
   -- No ICU for language "und", fallback to 'natural' table.sort
9
   und = function (t, _, comparator)
UNCOV
10
      if comparator then
×
UNCOV
11
         table.sort(t, function (e1, e2)
×
UNCOV
12
            return comparator(e1, e2, function (s1, s2)
×
UNCOV
13
               return s1 < s2 and -1 or s1 > s2 and 1 or 0
×
14
            end)
15
         end)
16
      else
UNCOV
17
         table.sort(t)
×
18
      end
19
   end,
20
}
21

22
setmetatable(collatedSort, {
392✔
23
   __call = function (self, t, options, comparator)
UNCOV
24
      local lang = SILE.settings:get("document.language")
×
UNCOV
25
      if self[lang] and type(self[lang]) == "function" then
×
26
         -- Allow overriding ICU for some languages, typically "und"
27
         return self[lang](t, options, comparator)
×
28
      end
29

UNCOV
30
      if self[lang] and type(self[lang]) == "table" then
×
31
         -- Allow customizing the default collation options for some languages
UNCOV
32
         options = options or self[lang]
×
33
      end
34
      -- Be efficient: create the collator once before sorting.
35
      -- I don't think we need to cache it, still.
UNCOV
36
      local collator = icu.collation_create(lang, options or {})
×
37

38
      local stringCompareClosure = function (s1, s2)
UNCOV
39
         return icu.compare(collator, s1, s2)
×
40
      end
UNCOV
41
      table.sort(t, function (e1, e2)
×
42
         -- Allow custom comparison function, notably for complex objects
43
         -- Pass the stringCompare function so that it can be used.
UNCOV
44
         if comparator then
×
UNCOV
45
            return comparator(e1, e2, stringCompareClosure)
×
46
         end
UNCOV
47
         return stringCompareClosure(e1, e2) < 0
×
48
      end)
UNCOV
49
      icu.collation_destroy(collator)
×
50
   end,
51
})
52

53
return collatedSort
196✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc