aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-01-25 17:28:21 +0000
committerLewis Russell <lewis6991@gmail.com>2023-01-26 10:02:00 +0000
commit9a9129c60b76cdfae5752071ec4c998c2f873c7c (patch)
tree0f72d67830f3e7b25529a7dffd3361366a83d5e1
parent0f3fa5a30a6433ab32cfb3aaed946f858f7113a1 (diff)
downloadrneovim-9a9129c60b76cdfae5752071ec4c998c2f873c7c.tar.gz
rneovim-9a9129c60b76cdfae5752071ec4c998c2f873c7c.tar.bz2
rneovim-9a9129c60b76cdfae5752071ec4c998c2f873c7c.zip
refactor(option.c): factor out option prefix parsing
-rw-r--r--src/nvim/option.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index c511a8e622..a54dd4d877 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1179,19 +1179,25 @@ static set_op_T get_op(const char *arg)
return op;
}
-static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errbuf,
- size_t errbuflen, char **errmsg)
+static int get_option_prefix(char **argp)
{
- int prefix = 1; // 1: nothing, 0: "no", 2: "inv" in front of name
-
if (strncmp(*argp, "no", 2) == 0) {
- prefix = 0;
*argp += 2;
+ return 0;
} else if (strncmp(*argp, "inv", 3) == 0) {
- prefix = 2;
*argp += 3;
+ return 2;
}
+ return 1;
+}
+
+static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errbuf,
+ size_t errbuflen, char **errmsg)
+{
+ // 1: nothing, 0: "no", 2: "inv" in front of name
+ int prefix = get_option_prefix(argp);
+
char *arg = *argp;
// find end of name
@@ -1221,11 +1227,11 @@ static void do_set_option(int opt_flags, char **argp, bool *did_show, char *errb
key = find_key_option(arg + 1, true);
}
} else {
- len = 0;
// The two characters after "t_" may not be alphanumeric.
if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3]) {
len = 4;
} else {
+ len = 0;
while (ASCII_ISALNUM(arg[len]) || arg[len] == '_') {
len++;
}