OSDN Git Service

Unicode 12.1.0
[luatex-ja/luatexja.git] / tool / function_uax50.lua
1 kpse.set_program_name('luatex')
2 dofile(kpse.find_file('lualibs.lua'))
3
4 local function toX(a) return string.format('0x%X',a) end
5
6 local uax_revision = '12.1.0'
7 print('  -- UAX#50 for Unicode  ' ..  uax_revision)
8 local fh = io.open('VerticalOrientation-' .. uax_revision .. '.txt')
9 local t = {}
10
11 for c in fh:lines() do
12     if c:match('(%x+)%.%.(%x+)%s+;%sT-[rR]') then
13         local b, e = c:match('(%x+)%.%.(%x+)%s+;')
14         b, e = tonumber(b,16), tonumber(e,16)
15         for i=b,e do t[i]=true end
16     elseif c:match('(%x+)%s+;%sT-[rR]') then
17         local b = c:match('(%x+)%s+;')
18         t[tonumber(b,16)]=true
19     end
20 end
21
22 fh:close()
23 local t2={}
24 local b, v = 0, t[0]
25 for i=0,0x10ffff do
26     if t[i]~=v then
27         table.insert(t2,b); b, v=i, t[i]
28     end
29 end
30 table.insert(t2,b)
31
32 print('  -- t[0] = ' .. tostring(t[0]))
33 print(table.serialize(t2,'  local t'))
34
35 --[[
36 for i,v in ipairs(t2) do
37     print(i, toX(v[1]) .. ' ≦x< ' .. toX(v[2]),  v[3])
38 end
39 ]]
40
41 print([[  local function rotate_in_uax50(i)
42     local lo, hi = 1, #t
43     while lo < hi do
44       local mi = math.ceil((lo+hi)/2)
45       if t[mi]<=i then lo=mi else hi=mi-1 end 
46     end
47     return lo%2==1
48   end
49 ]])
50