From 0c1bc129da3f684b04d72530dddaedb5255f12ef Mon Sep 17 00:00:00 2001 From: JINNOUCHI Yasushi Date: Tue, 15 Jun 2021 03:47:33 +0900 Subject: chore: use plenary.strings and remove strings functions from utils (#690) Co-authored-by: Simon Hauser --- lua/telescope/utils.lua | 94 ++++++------------------------------------------- 1 file changed, 10 insertions(+), 84 deletions(-) (limited to 'lua/telescope/utils.lua') diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index d9e4ec0..3938bae 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -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 +utils.strdisplaywidth = function() + error("strdisplaywidth deprecated. please use plenary.strings.strdisplaywidth") +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 +utils.utf_ptr2len = function() + error("utf_ptr2len deprecated. please use plenary.strings.utf_ptr2len") +end - return str:sub(nbyte + 1, nbyte + len) +utils.strcharpart = function() + error("strcharpart deprecated. please use plenary.strings.strcharpart") 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.align_str = function() + error("align_str deprecated. please use plenary.strings.align_str") end utils.transform_devicons = (function() -- cgit v1.2.3