diff options
author | Illia Bobyr <illia.bobyr@gmail.com> | 2023-10-17 11:09:45 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-10-17 11:09:45 +0200 |
commit | 6e6386716f9494ae86027c6d34f657fd03dfec42 (patch) | |
tree | 4a6c57ffec25e0af23238b2c23bd038eb2a2c86f /src/typval.c | |
parent | 2e3cd52fa02b1a208c97992b1bca3b04f7be66d4 (diff) |
patch 9.0.2040: trim(): hard to use default maskv9.0.2040
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>
Diffstat (limited to 'src/typval.c')
-rw-r--r-- | src/typval.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/typval.c b/src/typval.c index 08dd2313f2..b6371aaa43 100644 --- a/src/typval.c +++ b/src/typval.c @@ -451,6 +451,37 @@ check_for_opt_string_arg(typval_T *args, int idx) } /* + * Check for an optional string argument at 'idx', that can also be 'v:none' to + * use the default value. + * + * If 'is_none' is non-NULL it is set to 0 and updated to 1 when "args[idx]" is + * 'v:none'. + */ + int +check_for_opt_string_or_none_arg(typval_T *args, int idx, int *is_none) +{ + if (is_none != NULL) + *is_none = 0; + + if (args[idx].v_type == VAR_UNKNOWN) + return OK; + + if (args[idx].v_type == VAR_SPECIAL + && args[idx].vval.v_number == VVAL_NONE) + { + if (is_none != NULL) + *is_none = 1; + return OK; + } + + if (args[idx].v_type == VAR_STRING) + return OK; + + semsg(_(e_string_or_none_required_for_argument_nr), idx + 1); + return FAIL; +} + +/* * Give an error and return FAIL unless "args[idx]" is a number. */ int |