1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-01 07:00:05 +08:00
SpaceVim/lua/spacevim/api/data/string.lua

123 lines
2.0 KiB
Lua
Raw Normal View History

2022-05-27 10:22:16 +08:00
local str = {}
function str.trim(str)
=======
2022-02-03 23:10:41 +08:00
--=============================================================================
-- string.lua --- spacevim data#string api
-- Copyright (c) 2016-2019 Wang Shidong & Contributors
-- Author: Wang Shidong < wsdjeg@outlook.com >
-- URL: https://spacevim.org
-- License: GPLv3
--=============================================================================
2020-09-19 22:57:11 +08:00
2022-02-03 23:10:41 +08:00
local M = {}
2020-09-19 22:57:11 +08:00
2022-02-03 23:10:41 +08:00
function M.trim(str)
2022-05-27 10:22:16 +08:00
2020-09-19 22:57:11 +08:00
return str:match( "^%s*(.-)%s*$" )
end
2022-05-27 10:22:16 +08:00
function str.fill(str, length, ...)
if string.len(str) > length then
end
end
return str
=======
2022-02-03 23:10:41 +08:00
function M.fill(str, length, ...)
local v = ''
if string.len(str) <= length then
v = str
else
local rightmost= 0
while string.len(string.sub(str, 0, rightmost)) < length do
rightmost = rightmost + 1
end
end
v = string.sub(str, 0, rightmost)
local argvs = ...
local char = ' '
if argvs ~= nil then
char = argvs[1] or char
2020-09-19 22:57:11 +08:00
end
2022-02-03 23:10:41 +08:00
return v .. string.rep(char, length - string.len(v))
end
function M.strcharpart(str, start, ...)
2020-09-19 22:57:11 +08:00
end
2022-02-03 23:10:41 +08:00
function M.toggle_case(str)
local chars = {}
for _, char in pairs(M.string2chars(str)) do
local cn = string.byte(char)
if cn >= 97 and cn <= 122 then
table.insert(chars, string.char(cn - 32))
elseif cn >= 65 and cn <= 90 then
table.insert(chars, string.char(cn + 32))
else
table.insert(chars, char)
end
end
return table.concat(chars, '')
end
function M.fill_left(str)
end
function M.fill_middle(str, length, ...)
end
function M.trim_start(str)
end
function M.trim_end(str)
end
function M.string2chars(str)
local t = {}
for k in string.gmatch(str, '.') do table.insert(t, k) end
return t
end
function M.matchstrpos(str, need, ...)
end
function M.strAllIndex(str, need, use_expr)
end
function M.strQ2B(str)
end
function M.strB2Q(str)
end
function M.split(str, ...)
end
2020-09-19 22:57:11 +08:00
2022-02-03 23:10:41 +08:00
return M
2020-09-19 22:57:11 +08:00
2022-05-27 10:22:16 +08:00
2019-07-11 18:26:29 +08:00
-- @todo add lua string api
2020-09-19 22:57:11 +08:00