diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-01-25 17:12:21 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2023-01-26 10:02:00 +0000 |
commit | 0f3fa5a30a6433ab32cfb3aaed946f858f7113a1 (patch) | |
tree | 3248f2b8ed422fb995d17e805962c8f73d801afa /src | |
parent | 25310af06085c243c2b72a6a0f21cc45ce86a283 (diff) | |
download | rneovim-0f3fa5a30a6433ab32cfb3aaed946f858f7113a1.tar.gz rneovim-0f3fa5a30a6433ab32cfb3aaed946f858f7113a1.tar.bz2 rneovim-0f3fa5a30a6433ab32cfb3aaed946f858f7113a1.zip |
refactor(option.c): factor out set op parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/option.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index a4e48f9c02..c511a8e622 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1164,6 +1164,21 @@ static void do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, *argp = arg; } +static set_op_T get_op(const char *arg) +{ + set_op_T op = OP_NONE; + if (*arg != NUL && *(arg + 1) == '=') { + if (*arg == '+') { + op = OP_ADDING; // "+=" + } else if (*arg == '^') { + op = OP_PREPENDING; // "^=" + } else if (*arg == '-') { + op = OP_REMOVING; // "-=" + } + } + return op; +} + static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errbuf, size_t errbuflen, char **errmsg) { @@ -1229,19 +1244,11 @@ static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errb len++; } - set_op_T op = OP_NONE; - if (arg[len] != NUL && arg[len + 1] == '=') { - if (arg[len] == '+') { - op = OP_ADDING; // "+=" - len++; - } else if (arg[len] == '^') { - op = OP_PREPENDING; // "^=" - len++; - } else if (arg[len] == '-') { - op = OP_REMOVING; // "-=" - len++; - } + set_op_T op = get_op(arg + len); + if (op != OP_NONE) { + len++; } + uint8_t nextchar = (uint8_t)arg[len]; // next non-white char after option name if (opt_idx == -1 && key == 0) { // found a mismatch: skip |