diff options
author | Hans Hagen <pragma@wxs.nl> | 2018-12-17 18:19:48 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2018-12-17 18:19:48 +0100 |
commit | 15b67b20aa0d6c508578d0ca8cbdcd9cff9829a8 (patch) | |
tree | d656b4161487a8c54d954458084914c7d408aca7 /tex/generic/context/luatex/luatex-basics-gen.lua | |
parent | 5bb786877a5617fb8fbe3fd0e7b54fbcea3ce002 (diff) | |
download | context-15b67b20aa0d6c508578d0ca8cbdcd9cff9829a8.tar.gz |
2018-12-17 16:49:00
Diffstat (limited to 'tex/generic/context/luatex/luatex-basics-gen.lua')
-rw-r--r-- | tex/generic/context/luatex/luatex-basics-gen.lua | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tex/generic/context/luatex/luatex-basics-gen.lua b/tex/generic/context/luatex/luatex-basics-gen.lua index ee0367fa4..3959ca022 100644 --- a/tex/generic/context/luatex/luatex-basics-gen.lua +++ b/tex/generic/context/luatex/luatex-basics-gen.lua @@ -414,3 +414,66 @@ if not number.idiv then return floor(i/d) -- i//d in 5.3 end end + +-- hook into unicode + +local u = unicode and unicode.utf8 + +if u then + + utf.lower = u.lower + utf.upper = u.upper + utf.char = u.char + utf.byte = u.byte + utf.len = u.len + + -- needed on font-* + + if lpeg.setutfcasers then + lpeg.setutfcasers(u.lower,u.upper) + end + + -- needed on font-otr + + local bytepairs = string.bytepairs + local utfchar = utf.char + local concat = table.concat + + function utf.utf16_to_utf8_be(s) + if not s then + return nil + elseif s == "" then + return "" + end + local result, r, more = { }, 0, 0 + for left, right in bytepairs(s) do + if right then + local now = 256*left + right + if more > 0 then + now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000 + more = 0 + r = r + 1 + result[r] = utfchar(now) + elseif now >= 0xD800 and now <= 0xDBFF then + more = now + else + r = r + 1 + result[r] = utfchar(now) + end + end + end + return concat(result) + end + + local characters = string.utfcharacters + + function utf.split(str) + local t, n = { }, 0 + for s in characters(str) do + n = n + 1 + t[n] = s + end + return t + end + +end |