* Refactor bidi.lua (resolving weak types)

This commit is contained in:
Nils Dagsson Moskopp 2023-03-22 18:22:17 +01:00
parent 82d04cee6f
commit 4d8bea08fd
1 changed files with 56 additions and 16 deletions

View File

@ -77,16 +77,15 @@ bidi.get_visual_reordering = function(codepoints)
return codepoints_reordered
end
bidi.resolve_weak_types = function(run, sos)
for i, element in ipairs(run) do
-- W1
bidi.W1 = function(run, sos)
-- Examine each nonspacing mark (NSM) in the isolating run
-- sequence, and change the type of the NSM to Other Neutral
-- if the previous character is an isolate initiator or PDI,
-- and to the type of the previous character otherwise. If
-- the NSM is at the start of the isolating run sequence, it
-- will get the type of sos.
for i = 1, #run do
if "NSM" == run[i].bidi_class then
-- Examine each nonspacing mark (NSM) in the isolating run
-- sequence, and change the type of the NSM to Other Neutral
-- if the previous character is an isolate initiator or PDI,
-- and to the type of the previous character otherwise. If
-- the NSM is at the start of the isolating run sequence, it
-- will get the type of sos.
if 1 == i then
run[i].bidi_class = sos
else
@ -94,7 +93,12 @@ bidi.resolve_weak_types = function(run, sos)
run[i].bidi_class = run[i-1].bidi_class
end
end
-- W2
end
return run
end
bidi.W2 = function(run, sos)
for i = 1, #run do
if "EN" == run[i].bidi_class then
-- Search backward from each instance of a European number
-- until the first strong type (R, L, AL, or sos) is found.
@ -121,12 +125,22 @@ bidi.resolve_weak_types = function(run, sos)
run[i].bidi_class = "R"
end
end
-- W3
end
return run
end
bidi.W3 = function(run)
-- Change al ALs to R.
for i = 1, #run do
if "AL" == run[i].bidi_class then
-- Change al ALs to R.
run[i].bidi_class = "R"
end
-- W4
end
return run
end
bidi.W4 = function(run)
for i = 1, #run do
if "ES" == run[i].bidi_class then
-- A single European separator between two European numbers
-- changes to a European number.
@ -159,7 +173,12 @@ bidi.resolve_weak_types = function(run, sos)
run[i].bidi_class = "AN"
end
end
-- W5
end
return run
end
bidi.W5 = function(run)
for i = 1, #run do
if "ET" == run[i].bidi_class then
-- A sequence of European terminators adjacent to European
-- numbers changes to all European numbers.
@ -173,7 +192,12 @@ bidi.resolve_weak_types = function(run, sos)
run[i].bidi_class = "EN"
end
end
-- W6
end
return run
end
bidi.W6 = function(run)
for i = 1, #run do
if (
"ES" == run[i].bidi_class or
"ET" == run[i].bidi_class or
@ -183,7 +207,12 @@ bidi.resolve_weak_types = function(run, sos)
-- Neutral.
run[i].bidi_class = "ON"
end
-- W7
end
return run
end
bidi.W7 = function(run, sos)
for i = 1, #run do
if "EN" == run[i].bidi_class then
-- Search backward from each instance of a European number
-- until the first strong type (R, L, or sos) is found. If an
@ -213,6 +242,17 @@ bidi.resolve_weak_types = function(run, sos)
return run
end
bidi.resolve_weak_types = function(run, sos)
run = bidi.W1(run, sos)
run = bidi.W2(run, sos)
run = bidi.W3(run)
run = bidi.W4(run)
run = bidi.W5(run)
run = bidi.W6(run)
run = bidi.W7(run, sos)
return run
end
bidi.resolve_ni_types = function(run, embedding_direction)
for i, element in ipairs(run) do
-- N0