comparison src/typval.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 def9fc5c92d1
children e9c70470fe94
comparison
equal deleted inserted replaced
33590:d7220eebaf1a 33591:288da62613ba
446 int 446 int
447 check_for_opt_string_arg(typval_T *args, int idx) 447 check_for_opt_string_arg(typval_T *args, int idx)
448 { 448 {
449 return (args[idx].v_type == VAR_UNKNOWN 449 return (args[idx].v_type == VAR_UNKNOWN
450 || check_for_string_arg(args, idx) != FAIL) ? OK : FAIL; 450 || check_for_string_arg(args, idx) != FAIL) ? OK : FAIL;
451 }
452
453 /*
454 * Check for an optional string argument at 'idx', that can also be 'v:none' to
455 * use the default value.
456 *
457 * If 'is_none' is non-NULL it is set to 0 and updated to 1 when "args[idx]" is
458 * 'v:none'.
459 */
460 int
461 check_for_opt_string_or_none_arg(typval_T *args, int idx, int *is_none)
462 {
463 if (is_none != NULL)
464 *is_none = 0;
465
466 if (args[idx].v_type == VAR_UNKNOWN)
467 return OK;
468
469 if (args[idx].v_type == VAR_SPECIAL
470 && args[idx].vval.v_number == VVAL_NONE)
471 {
472 if (is_none != NULL)
473 *is_none = 1;
474 return OK;
475 }
476
477 if (args[idx].v_type == VAR_STRING)
478 return OK;
479
480 semsg(_(e_string_or_none_required_for_argument_nr), idx + 1);
481 return FAIL;
451 } 482 }
452 483
453 /* 484 /*
454 * Give an error and return FAIL unless "args[idx]" is a number. 485 * Give an error and return FAIL unless "args[idx]" is a number.
455 */ 486 */