mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 07:10:06 +08:00
feat(lua): add lua data#string
api
This commit is contained in:
parent
fcd0d28a67
commit
d356ef5bd2
@ -3,15 +3,16 @@
|
||||
"alternate": "test/api/{}.vader",
|
||||
"doc": "docs/api/{}.md"
|
||||
},
|
||||
"autoload/SpaceVim/plugins/a.vim": {
|
||||
"alternate": "test/plugin/a.vader",
|
||||
"lua" : "lua/spacevim/plugin/a.lua"
|
||||
"autoload/SpaceVim/plugins/*.vim": {
|
||||
"alternate": "test/plugin/{}.vader",
|
||||
"lua" : "lua/spacevim/plugin/{}.lua"
|
||||
},
|
||||
"lua/spacevim/plugin/a.lua": {
|
||||
"alternate": "test/lua/plugin/a.vader",
|
||||
"vim" : "autoload/SpaceVim/plugins/a.vim"
|
||||
"lua/spacevim/plugin/*.lua": {
|
||||
"alternate": "test/lua/plugin/{}.vader",
|
||||
"vim" : "autoload/SpaceVim/plugins/{}.vim"
|
||||
},
|
||||
"test/plugin/a.vader": { "alternate": "autoload/SpaceVim/plugins/a.vim" },
|
||||
"test/plugin/*.vader": { "alternate": "autoload/SpaceVim/plugins/{}.vim" },
|
||||
"test/lua/plugin/*.vader": { "alternate": "lua/spacevim/plugin/{}.lua" },
|
||||
"autoload/SpaceVim/layers/lang/*.vim": { "doc": "docs/layers/lang/{}.md" },
|
||||
"test/api/*.vader": { "alternate": "autoload/SpaceVim/api/{}.vim" },
|
||||
"docs/layers/*.md": {
|
||||
|
@ -1,20 +1,103 @@
|
||||
|
||||
local str = {}
|
||||
--=============================================================================
|
||||
-- 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
|
||||
--=============================================================================
|
||||
|
||||
|
||||
function str.trim(str)
|
||||
local M = {}
|
||||
|
||||
|
||||
function M.trim(str)
|
||||
return str:match( "^%s*(.-)%s*$" )
|
||||
end
|
||||
|
||||
|
||||
function str.fill(str, length, ...)
|
||||
if string.len(str) > length then
|
||||
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
|
||||
end
|
||||
return v .. string.rep(char, length - string.len(v))
|
||||
end
|
||||
|
||||
function M.strcharpart(str, start, ...)
|
||||
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
|
||||
return str
|
||||
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
|
||||
|
||||
return M
|
||||
|
||||
-- @todo add lua string api
|
||||
|
||||
|
9
test/lua/data/string.vader
Normal file
9
test/lua/data/string.vader
Normal file
@ -0,0 +1,9 @@
|
||||
Execute ( SpaceVim lua api: data#string ):
|
||||
if $SPACEVIM_LUA != 1
|
||||
finish
|
||||
endif
|
||||
let cmp = SpaceVim#api#import('vim#compatible')
|
||||
Log 'test trim()'
|
||||
lua sp_str = require('spacevim.api').import('data.string')
|
||||
AssertEqual cmp.luaeval("sp_str.trim(' s b ')"), 's b'
|
||||
|
0
test/lua/plugin/projectmanager.vader
Normal file
0
test/lua/plugin/projectmanager.vader
Normal file
0
test/plugin/projectmanager.vader
Normal file
0
test/plugin/projectmanager.vader
Normal file
Loading…
Reference in New Issue
Block a user