mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
lua/shared: share trim() impl
This commit is contained in:
@@ -374,11 +374,6 @@ For example, to use the "nvim_get_current_line()" API function, call
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
VIM *lua-util*
|
VIM *lua-util*
|
||||||
|
|
||||||
vim.inspect({object}, {options}) *vim.inspect*
|
|
||||||
Return a human-readable representation of the passed object. See
|
|
||||||
https://github.com/kikito/inspect.lua
|
|
||||||
for details and possible options.
|
|
||||||
|
|
||||||
vim.stricmp(a, b) *lua-vim.stricmp*
|
vim.stricmp(a, b) *lua-vim.stricmp*
|
||||||
Function used for case-insensitive string comparison. Takes two
|
Function used for case-insensitive string comparison. Takes two
|
||||||
string arguments and returns 0, 1 or -1 if strings are equal, a is
|
string arguments and returns 0, 1 or -1 if strings are equal, a is
|
||||||
@@ -422,18 +417,11 @@ vim.types *lua-vim.types*
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
Lua module: vim *lua-vim*
|
Lua module: vim *lua-vim*
|
||||||
|
|
||||||
trim({s}) *vim.trim()*
|
inspect({object}, {options}) *vim.inspect()*
|
||||||
Trim whitespace (Lua pattern "%%s") from both sides of a
|
Return a human-readable representation of the given object.
|
||||||
string.
|
|
||||||
|
|
||||||
Parameters: ~
|
|
||||||
{s} String to trim
|
|
||||||
|
|
||||||
Return: ~
|
|
||||||
String with whitespace removed from its beginning and end
|
|
||||||
|
|
||||||
See also: ~
|
See also: ~
|
||||||
https://www.lua.org/pil/20.2.html
|
https://github.com/kikito/inspect.lua
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -521,4 +509,17 @@ tbl_flatten({t}) *vim.tbl_flatten()*
|
|||||||
Return: ~
|
Return: ~
|
||||||
Flattened copy of the given list-like table.
|
Flattened copy of the given list-like table.
|
||||||
|
|
||||||
|
trim({s}) *vim.trim()*
|
||||||
|
Trim whitespace (Lua pattern "%%s") from both sides of a
|
||||||
|
string.
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
{s} String to trim
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
String with whitespace removed from its beginning and end
|
||||||
|
|
||||||
|
See also: ~
|
||||||
|
https://www.lua.org/pil/20.2.html
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:
|
vim:tw=78:ts=8:ft=help:norl:
|
||||||
|
@@ -168,6 +168,16 @@ local function tbl_flatten(t)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Trim whitespace (Lua pattern "%%s") from both sides of a string.
|
||||||
|
---
|
||||||
|
--@see https://www.lua.org/pil/20.2.html
|
||||||
|
--@param s String to trim
|
||||||
|
--@returns String with whitespace removed from its beginning and end
|
||||||
|
local function trim(s)
|
||||||
|
assert(type(s) == 'string', 'Only strings can be trimmed')
|
||||||
|
return s:match('^%s*(.*%S)') or ''
|
||||||
|
end
|
||||||
|
|
||||||
local module = {
|
local module = {
|
||||||
deepcopy = deepcopy,
|
deepcopy = deepcopy,
|
||||||
gsplit = gsplit,
|
gsplit = gsplit,
|
||||||
@@ -175,5 +185,6 @@ local module = {
|
|||||||
tbl_contains = tbl_contains,
|
tbl_contains = tbl_contains,
|
||||||
tbl_extend = tbl_extend,
|
tbl_extend = tbl_extend,
|
||||||
tbl_flatten = tbl_flatten,
|
tbl_flatten = tbl_flatten,
|
||||||
|
trim = trim,
|
||||||
}
|
}
|
||||||
return module
|
return module
|
||||||
|
@@ -154,14 +154,11 @@ local function _update_package_paths()
|
|||||||
last_nvim_paths = cur_nvim_paths
|
last_nvim_paths = cur_nvim_paths
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Trim whitespace (Lua pattern "%%s") from both sides of a string.
|
--- Return a human-readable representation of the given object.
|
||||||
---
|
---
|
||||||
--@see https://www.lua.org/pil/20.2.html
|
--@see https://github.com/kikito/inspect.lua
|
||||||
--@param s String to trim
|
local function inspect(object, options) -- luacheck: no unused
|
||||||
--@returns String with whitespace removed from its beginning and end
|
error(object, options) -- Stub for gen_vimdoc.py
|
||||||
local function trim(s)
|
|
||||||
assert(type(s) == 'string', 'Only strings can be trimmed')
|
|
||||||
return s:match('^%s*(.*%S)') or ''
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function __index(t, key)
|
local function __index(t, key)
|
||||||
@@ -180,7 +177,6 @@ local module = {
|
|||||||
_os_proc_children = _os_proc_children,
|
_os_proc_children = _os_proc_children,
|
||||||
_os_proc_info = _os_proc_info,
|
_os_proc_info = _os_proc_info,
|
||||||
_system = _system,
|
_system = _system,
|
||||||
trim = trim,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setmetatable(module, {
|
setmetatable(module, {
|
||||||
|
@@ -717,7 +717,7 @@ int os_setperm(const char *const name, int perm)
|
|||||||
/// @return 0 on success, or libuv error code on failure.
|
/// @return 0 on success, or libuv error code on failure.
|
||||||
///
|
///
|
||||||
/// @note If `owner` or `group` is -1, then that ID is not changed.
|
/// @note If `owner` or `group` is -1, then that ID is not changed.
|
||||||
int os_chown(const char* path, uv_uid_t owner, uv_gid_t group)
|
int os_chown(const char *path, uv_uid_t owner, uv_gid_t group)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
RUN_UV_FS_FUNC(r, uv_fs_chown, path, owner, group, NULL);
|
RUN_UV_FS_FUNC(r, uv_fs_chown, path, owner, group, NULL);
|
||||||
|
@@ -697,10 +697,6 @@ local function read_nvim_log()
|
|||||||
return log
|
return log
|
||||||
end
|
end
|
||||||
|
|
||||||
local function trim(s)
|
|
||||||
return s:match('^%s*(.*%S)') or ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local module = {
|
local module = {
|
||||||
REMOVE_THIS = REMOVE_THIS,
|
REMOVE_THIS = REMOVE_THIS,
|
||||||
argss_to_cmd = argss_to_cmd,
|
argss_to_cmd = argss_to_cmd,
|
||||||
@@ -740,7 +736,6 @@ local module = {
|
|||||||
updated = updated,
|
updated = updated,
|
||||||
which = which,
|
which = which,
|
||||||
write_file = write_file,
|
write_file = write_file,
|
||||||
trim = trim,
|
|
||||||
}
|
}
|
||||||
module = shared.tbl_extend('error', module, Paths, shared)
|
module = shared.tbl_extend('error', module, Paths, shared)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user