From 8823c59ae9a86ecd8b765d5f936be894582777dc Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 25 Dec 2013 22:32:54 +0100 Subject: sync with Context as of 2013-12-25 --- lualibs-table.lua | 9 ++++++--- lualibs-unicode.lua | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lualibs-table.lua b/lualibs-table.lua index c6bbc62..f361f3d 100644 --- a/lualibs-table.lua +++ b/lualibs-table.lua @@ -129,10 +129,13 @@ local function sortedhash(t,cmp) s = sortedkeys(t) -- the robust one end local n = 0 + local m = #s local function kv(s) - n = n + 1 - local k = s[n] - return k, t[k] + if n < m then + n = n + 1 + local k = s[n] + return k, t[k] + end end return kv, s else diff --git a/lualibs-unicode.lua b/lualibs-unicode.lua index 902f6a0..6601a4c 100644 --- a/lualibs-unicode.lua +++ b/lualibs-unicode.lua @@ -9,7 +9,6 @@ if not modules then modules = { } end modules ['l-unicode'] = { -- this module will be reorganized -- todo: utf.sub replacement (used in syst-aux) - -- we put these in the utf namespace: utf = utf or (unicode and unicode.utf8) or { } @@ -1130,3 +1129,13 @@ if not utf.values then string.utfvalues = utf.values end + +function utf.chrlen(u) -- u is number + return + (u < 0x80 and 1) or + (u < 0xE0 and 2) or + (u < 0xF0 and 3) or + (u < 0xF8 and 4) or + (u < 0xFC and 5) or + (u < 0xFE and 6) or 0 +end -- cgit v1.2.3