chore: use plenary.strings and remove strings functions from utils (#690)

Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
This commit is contained in:
JINNOUCHI Yasushi
2021-06-15 03:47:33 +09:00
committed by GitHub
parent 398a0d391a
commit 0c1bc129da
6 changed files with 25 additions and 139 deletions

View File

@@ -377,94 +377,20 @@ function utils.get_os_command_output(cmd, cwd)
return stdout, ret, stderr
end
utils.strdisplaywidth = (function()
if jit and pathlib.separator ~= '\\' then
local ffi = require('ffi')
ffi.cdef[[
typedef unsigned char char_u;
int linetabsize_col(int startcol, char_u *s);
]]
return function(str, col)
local startcol = col or 0
str = tostring(str)
local s = ffi.new('char[?]', #str + 1)
ffi.copy(s, str)
return ffi.C.linetabsize_col(startcol, s) - startcol
end
else
return function(str, col)
return #(tostring(str)) - (col or 0)
end
end
end)()
utils.utf_ptr2len = (function()
if jit and pathlib.separator ~= '\\' then
local ffi = require('ffi')
ffi.cdef[[
typedef unsigned char char_u;
int utf_ptr2len(const char_u *const p);
]]
return function(str)
local c_str = ffi.new('char[?]', #str + 1)
ffi.copy(c_str, str)
return ffi.C.utf_ptr2len(c_str)
end
else
return function(str)
return str == '' and 0 or 1
end
end
end)()
function utils.strcharpart(str, nchar, charlen)
local nbyte = 0
if nchar > 0 then
while nchar > 0 and nbyte < #str do
nbyte = nbyte + utils.utf_ptr2len(str:sub(nbyte + 1))
nchar = nchar - 1
end
else
nbyte = nchar
end
local len = 0
if charlen then
while charlen > 0 and nbyte + len < #str do
local off = nbyte + len
if off < 0 then
len = len + 1
else
len = len + utils.utf_ptr2len(str:sub(off + 1))
end
charlen = charlen - 1
end
else
len = #str - nbyte
end
if nbyte < 0 then
len = len + nbyte
nbyte = 0
elseif nbyte > #str then
nbyte = #str
end
if len < 0 then
len = 0
elseif nbyte + len > #str then
len = #str - nbyte
end
return str:sub(nbyte + 1, nbyte + len)
utils.strdisplaywidth = function()
error("strdisplaywidth deprecated. please use plenary.strings.strdisplaywidth")
end
utils.align_str = function(string, width, right_justify)
local str_len = utils.strdisplaywidth(string)
return right_justify
and string.rep(" ", width - str_len)..string
or string..string.rep(" ", width - str_len)
utils.utf_ptr2len = function()
error("utf_ptr2len deprecated. please use plenary.strings.utf_ptr2len")
end
utils.strcharpart = function()
error("strcharpart deprecated. please use plenary.strings.strcharpart")
end
utils.align_str = function()
error("align_str deprecated. please use plenary.strings.align_str")
end
utils.transform_devicons = (function()