summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <megas.kapaneus@gmail.com>2011-05-10 18:52:28 +0200
committerPhilipp Gesang <megas.kapaneus@gmail.com>2011-05-10 18:52:28 +0200
commit3125c85ca062459ddd50eb9c1d80b35d358deacb (patch)
tree5de151a5341863bf4515bed52d9874f02638dcbe
parentee619e501e4e117bc8ddfe55bf58f0e7a21b5e4a (diff)
downloadtransliterator-3125c85ca062459ddd50eb9c1d80b35d358deacb.tar.gz
yet more general Serbian exception handling
-rw-r--r--tex/context/third/transliterator/trans_tables_sr.lua50
1 files changed, 32 insertions, 18 deletions
diff --git a/tex/context/third/transliterator/trans_tables_sr.lua b/tex/context/third/transliterator/trans_tables_sr.lua
index 446f688..8a4744a 100644
--- a/tex/context/third/transliterator/trans_tables_sr.lua
+++ b/tex/context/third/transliterator/trans_tables_sr.lua
@@ -98,24 +98,38 @@ if not translit.done_serbian then
local P = lpeg.P
local sub, upper = unicode.utf8.sub, unicode.utf8.upper
- local sre, srei, p_sre, p_sre_i = { }, { }
- for lat, cyr in next, except do
- local Lat = upper(sub(lat, 1, 1)) .. sub(lat, 2)
- local Cyr = upper(sub(cyr, 1, 1)) .. sub(cyr, 2)
- local LAT, CYR = upper(lat), upper(cyr)
- local p_lat = P" " * (P(lat) + Lat + LAT)
-
- p_sre_i = p_sre_i and p_sre_i + P(lat) + Lat + LAT or P(lat) + Lat + LAT
- p_sre = p_sre and p_sre + p_lat or p_lat
-
- srei[lat], srei[Lat], srei[LAT] = cyr, Cyr, CYR
- sre[" "..lat], sre[" "..Lat], sre[" "..LAT] = " "..cyr, " "..Cyr, " "..CYR
+ --local e_tocy, e_i_tocy, e_tolt, e_i_tolt = { }, { }, { }, { }
+ local p_tocy, p_i_tocy, p_tolt, p_i_tolt
+
+ for left, right in next, except do -- generating exception patterns for both sides
+ local Left = upper(sub(left, 1, 1)) .. sub(left, 2)
+ local Right = upper(sub(right, 1, 1)) .. sub(right, 2)
+ local LEFT, RIGHT = upper(left), upper(right)
+
+ local p_i_left = P(left) / right + P(Left) / Right + P(LEFT) / RIGHT
+ local p_i_right = P(right) / left + P(Right) / Left + P(RIGHT) / LEFT
+
+ local p_left = P" " * p_i_left
+ local p_right = P" " * p_i_right
+
+ if not p_tocy then
+ p_tocy = p_left
+ p_i_tocy = p_i_left
+ p_tolt = p_right
+ p_i_tolt = p_i_right
+ else
+ p_tocy = p_tocy + p_left
+ p_i_tocy = p_i_tocy + p_i_left
+ p_tolt = p_tolt + p_right
+ p_i_tolt = p_i_tolt + p_i_right
+ end
end
- translit.serbian_exceptions = sre
- translit.serbian_exceptions_init = srei
- translit.p_serbian_exceptions = p_sre
- translit.p_serbian_exceptions_init = p_sre_i
+ translit.serbian_exceptions = { }
+ translit.serbian_exceptions.p_tocy = p_tocy
+ translit.serbian_exceptions.p_tolt = p_tolt
+ translit.serbian_exceptions.p_tocy_init = p_i_tocy
+ translit.serbian_exceptions.p_tolt_init = p_i_tolt
translit.done_serbian = true
end
@@ -129,8 +143,8 @@ local t = translit
local function sr (mode, text)
local P, R, Cs = lpeg.P, lpeg.R, lpeg.Cs
local utfchar = translit.utfchar
- local _p_sre = translit.p_serbian_exceptions / translit.serbian_exceptions
- local _p_sre_i = translit.p_serbian_exceptions_init / translit.serbian_exceptions_init
+ local _p_sre = t.serbian_exceptions["p_" .. mode:match("to..$")]
+ local _p_sre_i = t.serbian_exceptions["p_" .. mode:match("to..$") .. "_init"]
local trl_sr = translit.make_add_dict{}
trl_sr = t[mode.."_upper"] + t[mode.."_lower"]