diff options
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 07145c6e3f..1038a95dd3 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -168,6 +168,16 @@ local function tbl_flatten(t) return result 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 = { deepcopy = deepcopy, gsplit = gsplit, @@ -175,5 +185,6 @@ local module = { tbl_contains = tbl_contains, tbl_extend = tbl_extend, tbl_flatten = tbl_flatten, + trim = trim, } return module |