aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.lua9
-rw-r--r--src/nvim/strings.c4
2 files changed, 10 insertions, 3 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 46d17d8c03..eec3c68e0f 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -11805,15 +11805,18 @@ M.funcs = {
desc = [=[
Return {text} as a String where any character in {mask} is
removed from the beginning and/or end of {text}.
- If {mask} is not given, {mask} is all characters up to 0x20,
- which includes Tab, space, NL and CR, plus the non-breaking
- space character 0xa0.
+
+ If {mask} is not given, or is an empty string, {mask} is all
+ characters up to 0x20, which includes Tab, space, NL and CR,
+ plus the non-breaking space character 0xa0.
+
The optional {dir} argument specifies where to remove the
characters:
0 remove from the beginning and end of {text}
1 remove only at the beginning of {text}
2 remove only at the end of {text}
When omitted both ends are trimmed.
+
This function deals with multibyte characters properly.
Returns an empty string on error.
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index cc66f917f8..af82f5e578 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -2926,6 +2926,10 @@ void f_trim(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
if (argvars[1].v_type == VAR_STRING) {
mask = tv_get_string_buf_chk(&argvars[1], buf2);
+ if (*mask == NUL) {
+ mask = NULL;
+ }
+
if (argvars[2].v_type != VAR_UNKNOWN) {
bool error = false;
// leading or trailing characters to trim