summaryrefslogtreecommitdiff
path: root/mod/tex/context/third/rst/rst_helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'mod/tex/context/third/rst/rst_helpers.lua')
-rw-r--r--mod/tex/context/third/rst/rst_helpers.lua19
1 files changed, 12 insertions, 7 deletions
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