Comparison

util/human/io.lua @ 11897:e84ea5b58b29

util.human.io: Use UTF-8-aware length check in padding functions
author Kim Alvefur <zash@zash.se>
date Fri, 12 Nov 2021 14:22:21 +0100
parent 11896:93e9f7ae2f9b
child 12573:0f4feaf9ca64
comparison
equal deleted inserted replaced
11896:93e9f7ae2f9b 11897:e84ea5b58b29
91 local function printf(fmt, ...) 91 local function printf(fmt, ...)
92 print(fmt:format(...)); 92 print(fmt:format(...));
93 end 93 end
94 94
95 local function padright(s, width) 95 local function padright(s, width)
96 return s..string.rep(" ", width-#s); 96 return s..string.rep(" ", width-len(s));
97 end 97 end
98 98
99 local function padleft(s, width) 99 local function padleft(s, width)
100 return string.rep(" ", width-#s)..s; 100 return string.rep(" ", width-len(s))..s;
101 end 101 end
102 102
103 local pat = "[%z\001-\127\194-\253][\128-\191]*"; 103 local pat = "[%z\001-\127\194-\253][\128-\191]*";
104 local function utf8_cut(s, pos) 104 local function utf8_cut(s, pos)
105 return s:match("^"..pat:rep(pos)) or s; 105 return s:match("^"..pat:rep(pos)) or s;