mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.2040: trim(): hard to use default mask
Problem: trim(): hard to use default mask Solution: Use default 'mask' when it is v:none 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. 'v:none' is already used to mean "use the default argument value" in user defined functions. See |none-function_argument| in help. closes: #13363 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Illia Bobyr <illia.bobyr@gmail.com>
This commit is contained in:
committed by
Christian Brabandt
parent
2e3cd52fa0
commit
6e6386716f
@@ -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_arg(argvars, 1) == FAIL
|
||||
|| check_for_opt_string_or_none_arg(argvars, 1, NULL) == FAIL
|
||||
|| (argvars[1].v_type != VAR_UNKNOWN
|
||||
&& check_for_opt_number_arg(argvars, 2) == FAIL)))
|
||||
return;
|
||||
@@ -1971,26 +1971,24 @@ f_trim(typval_T *argvars, typval_T *rettv)
|
||||
if (head == NULL)
|
||||
return;
|
||||
|
||||
if (check_for_opt_string_arg(argvars, 1) == FAIL)
|
||||
if (check_for_opt_string_or_none_arg(argvars, 1, NULL) == FAIL)
|
||||
return;
|
||||
|
||||
if (argvars[1].v_type == VAR_STRING)
|
||||
{
|
||||
mask = tv_get_string_buf_chk(&argvars[1], buf2);
|
||||
|
||||
if (argvars[2].v_type != VAR_UNKNOWN)
|
||||
{
|
||||
int error = 0;
|
||||
if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN)
|
||||
{
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user