aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-05-20 23:06:14 +0200
committerJustin M. Keyes <justinkz@gmail.com>2019-05-20 23:46:56 +0200
commit5b04a4fa09e0ee09678aec23b1d0233e7c25e3e6 (patch)
tree04f75eccd24174f4723274a7505874d822363b9a /runtime/lua/vim
parent646c3423dd580aebb677d9a3fe0ed26f74f97e31 (diff)
downloadrneovim-5b04a4fa09e0ee09678aec23b1d0233e7c25e3e6.tar.gz
rneovim-5b04a4fa09e0ee09678aec23b1d0233e7c25e3e6.tar.bz2
rneovim-5b04a4fa09e0ee09678aec23b1d0233e7c25e3e6.zip
lua/shared: share trim() impl
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/shared.lua11
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