From 001738e26e1b841a4042b3597ba28d9c3d04aef6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Aug 2011 14:30:54 +0200 Subject: fixed solitary substitution bug (reported by Philipp A.) --- mod/tex/context/third/rst/rst_helpers.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'mod/tex/context/third/rst/rst_helpers.lua') diff --git a/mod/tex/context/third/rst/rst_helpers.lua b/mod/tex/context/third/rst/rst_helpers.lua index c348064..bbf1d1f 100644 --- a/mod/tex/context/third/rst/rst_helpers.lua +++ b/mod/tex/context/third/rst/rst_helpers.lua @@ -8,7 +8,6 @@ -------------------------------------------------------------------------------- -- -local utf = unicode.utf8 local P, R, S, V, match = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match @@ -20,9 +19,15 @@ helpers = thirddata.rst_helpers helpers.table = {} helpers.cell = {} +local utf = unicode.utf8 +local utflen = utf.len + +local stringstrip = string.strip +local fmt = string.format + function helpers.dbg_writef(...) if helpers.rst_debug then - io.write(string.format(...)) + io.write(fmt(...)) end end @@ -113,7 +118,7 @@ function helpers.cell.create(raw, n_row, n_col, parent, variant) local cell = {} cell.stripped = raw and p.strip:match(raw) or "" cell.content = raw - cell.width = raw and utf.len(raw) or 0 + cell.width = raw and utflen(raw) or 0 cell.bytes = raw and #raw or 0 cell.variant = "normal" -- [normal|separator|y_continue|x_continue] cell.pos = {} @@ -131,7 +136,7 @@ function helpers.cell.get_x_span(content, layout, init) local lw = layout.widths for n=init, #lw do acc = acc + lw[n] + 1 - if utf.len(content) + 1 == acc then + if utflen(content) + 1 == acc then return n - init end end @@ -215,7 +220,7 @@ function helpers.table.create(raw) this.variant = "empty1" end else - local cellwidth = utf.len(splitpos) + local cellwidth = utflen(splitpos) if cellwidth > layoutwidth then span = span + hc.get_x_span(splitpos, newtablayout, pos_layout) end @@ -367,7 +372,7 @@ function helpers.table.simple(raw) content = "", span = { x = 1, y = 1 }, } - cell.content = string.strip(row:sub(start, stop)) + cell.content = stringstrip(row:sub(start, stop)) if check_span then local start_at, stop_at for colnr, slice in ipairs(bounds.slices) do @@ -590,7 +595,7 @@ do -- This grammar inside the function is slightly faster than the same as an upvalue -- with the value of “width” repeatedly given via lpeg.Carg(). This holds -- for repeated calls as well. - local ulen = utf.len + local ulen = utflen function helpers.string.wrapat (str, width) local width = width or 65 local linelength = 0 -- cgit v1.2.3