summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/luatex/luatexja/tool/function_uax50.lua
blob: ea7871a6a8c4754d006c1ad22188d3ac3509e6b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
kpse.set_program_name('luatex')
dofile(kpse.find_file('lualibs.lua'))

local function toX(a) return string.format('0x%X',a) end

local uax_revision = '13.0.0'
print('  -- UAX#50 for Unicode  ' ..  uax_revision)
local fh = io.open('VerticalOrientation-' .. uax_revision .. '.txt')
local t = {}

for c in fh:lines() do
    if c:match('(%x+)%.%.(%x+)%s+;%sT-[rR]') then
	local b, e = c:match('(%x+)%.%.(%x+)%s+;')
	b, e = tonumber(b,16), tonumber(e,16)
	for i=b,e do t[i]=true end
    elseif c:match('(%x+)%s+;%sT-[rR]') then
	local b = c:match('(%x+)%s+;')
	t[tonumber(b,16)]=true
    end
end

fh:close()
local t2={}
local b, v = 0, t[0]
for i=0,0x10ffff do
    if t[i]~=v then
	table.insert(t2,b); b, v=i, t[i]
    end
end
table.insert(t2,b)

print('  -- t[0] = ' .. tostring(t[0]))
print(table.serialize(t2,'  local t'))

--[[
for i,v in ipairs(t2) do
    print(i, toX(v[1]) .. ' ≦x< ' .. toX(v[2]),  v[3])
end
]]

print([[  local function rotate_in_uax50(i)
    local lo, hi = 1, #t
    while lo < hi do
      local mi = math.ceil((lo+hi)/2)
      if t[mi]<=i then lo=mi else hi=mi-1 end 
    end
    return lo%2==1
  end
]])