Mercurial > vim
comparison src/strings.c @ 33591:288da62613ba v9.0.2040
patch 9.0.2040: trim(): hard to use default mask
Commit: https://github.com/vim/vim/commit/6e6386716f9494ae86027c6d34f657fd03dfec42
Author: Illia Bobyr <illia.bobyr@gmail.com>
Date: Tue Oct 17 11:09:45 2023 +0200
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>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 17 Oct 2023 11:15:09 +0200 |
parents | 8b7a2ea22a86 |
children | e9c70470fe94 |
comparison
equal
deleted
inserted
replaced
33590:d7220eebaf1a | 33591:288da62613ba |
---|---|
1960 rettv->v_type = VAR_STRING; | 1960 rettv->v_type = VAR_STRING; |
1961 rettv->vval.v_string = NULL; | 1961 rettv->vval.v_string = NULL; |
1962 | 1962 |
1963 if (in_vim9script() | 1963 if (in_vim9script() |
1964 && (check_for_string_arg(argvars, 0) == FAIL | 1964 && (check_for_string_arg(argvars, 0) == FAIL |
1965 || check_for_opt_string_arg(argvars, 1) == FAIL | 1965 || check_for_opt_string_or_none_arg(argvars, 1, NULL) == FAIL |
1966 || (argvars[1].v_type != VAR_UNKNOWN | 1966 || (argvars[1].v_type != VAR_UNKNOWN |
1967 && check_for_opt_number_arg(argvars, 2) == FAIL))) | 1967 && check_for_opt_number_arg(argvars, 2) == FAIL))) |
1968 return; | 1968 return; |
1969 | 1969 |
1970 head = tv_get_string_buf_chk(&argvars[0], buf1); | 1970 head = tv_get_string_buf_chk(&argvars[0], buf1); |
1971 if (head == NULL) | 1971 if (head == NULL) |
1972 return; | 1972 return; |
1973 | 1973 |
1974 if (check_for_opt_string_arg(argvars, 1) == FAIL) | 1974 if (check_for_opt_string_or_none_arg(argvars, 1, NULL) == FAIL) |
1975 return; | 1975 return; |
1976 | 1976 |
1977 if (argvars[1].v_type == VAR_STRING) | 1977 if (argvars[1].v_type == VAR_STRING) |
1978 { | |
1979 mask = tv_get_string_buf_chk(&argvars[1], buf2); | 1978 mask = tv_get_string_buf_chk(&argvars[1], buf2); |
1980 | 1979 |
1981 if (argvars[2].v_type != VAR_UNKNOWN) | 1980 if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) |
1982 { | 1981 { |
1983 int error = 0; | 1982 int error = 0; |
1984 | 1983 |
1985 // leading or trailing characters to trim | 1984 // leading or trailing characters to trim |
1986 dir = (int)tv_get_number_chk(&argvars[2], &error); | 1985 dir = (int)tv_get_number_chk(&argvars[2], &error); |
1987 if (error) | 1986 if (error) |
1988 return; | 1987 return; |
1989 if (dir < 0 || dir > 2) | 1988 if (dir < 0 || dir > 2) |
1990 { | 1989 { |
1991 semsg(_(e_invalid_argument_str), tv_get_string(&argvars[2])); | 1990 semsg(_(e_invalid_argument_str), tv_get_string(&argvars[2])); |
1992 return; | 1991 return; |
1993 } | |
1994 } | 1992 } |
1995 } | 1993 } |
1996 | 1994 |
1997 if (dir == 0 || dir == 1) | 1995 if (dir == 0 || dir == 1) |
1998 { | 1996 { |