1
0
forked from aniani/vim

patch 9.0.2041: trim(): hard to use default mask

Problem:  trim(): hard to use default mask (partly revert v9.0.2040)
Solution: use default mask when it is empty

The default 'mask' value is pretty complex, as it includes many
characters.  Yet, if one needs to specify the trimming direction, the
third argument, 'trim()' currently requires the 'mask' value to be
provided explicitly.

Currently, an empty 'mask' will make 'trim()' call return 'text' value
that is passed in unmodified.  It is unlikely that someone is using it,
so the chances of scripts being broken by this change are low.

Also, this reverts commit 9.0.2040 (which uses v:none for the default
and requires to use an empty string instead).

closes: #13358

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Illia Bobyr <illia.bobyr@gmail.com>
This commit is contained in:
Illia Bobyr
2023-10-17 18:00:50 +02:00
committed by Christian Brabandt
parent 5a33ce2a66
commit 8079917447
8 changed files with 27 additions and 56 deletions

View File

@@ -1962,7 +1962,7 @@ f_trim(typval_T *argvars, typval_T *rettv)
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_opt_string_or_none_arg(argvars, 1, NULL) == FAIL
|| check_for_opt_string_arg(argvars, 1) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN
&& check_for_opt_number_arg(argvars, 2) == FAIL)))
return;
@@ -1971,24 +1971,28 @@ f_trim(typval_T *argvars, typval_T *rettv)
if (head == NULL)
return;
if (check_for_opt_string_or_none_arg(argvars, 1, NULL) == FAIL)
if (check_for_opt_string_arg(argvars, 1) == FAIL)
return;
if (argvars[1].v_type == VAR_STRING)
mask = tv_get_string_buf_chk(&argvars[1], buf2);
if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN)
{
int error = 0;
mask = tv_get_string_buf_chk(&argvars[1], buf2);
if (*mask == NUL)
mask = NULL;
// leading or trailing characters to trim
dir = (int)tv_get_number_chk(&argvars[2], &error);
if (error)
return;
if (dir < 0 || dir > 2)
if (argvars[2].v_type != VAR_UNKNOWN)
{
semsg(_(e_invalid_argument_str), tv_get_string(&argvars[2]));
return;
int error = 0;
// leading or trailing characters to trim
dir = (int)tv_get_number_chk(&argvars[2], &error);
if (error)
return;
if (dir < 0 || dir > 2)
{
semsg(_(e_invalid_argument_str), tv_get_string(&argvars[2]));
return;
}
}
}