diff options
author | ZyX <kp-pav@yandex.ru> | 2014-07-13 11:15:55 +0400 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:43:43 +0300 |
commit | 459900b1005d8fd661d03d0e0bdae771a21b017b (patch) | |
tree | 717a32f0a8bb161cad17bacc312168aa538d62c1 | |
parent | ebabdff5cd24f2d30ab35051d1d65f7c29fa3dd3 (diff) | |
download | rneovim-459900b1005d8fd661d03d0e0bdae771a21b017b.tar.gz rneovim-459900b1005d8fd661d03d0e0bdae771a21b017b.tar.bz2 rneovim-459900b1005d8fd661d03d0e0bdae771a21b017b.zip |
option: Add findoption_len function
It is like findoption(), but works with non-NUL-terminated strings.
-rw-r--r-- | src/nvim/option.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 9942d154e1..b7521e38f8 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4286,10 +4286,10 @@ static void check_redraw(uint32_t flags) } /* - * Find index for option 'arg'. + * Find index for option 'arg' that has given length. * Return -1 if not found. */ -static int findoption(char_u *arg) +static int findoption_len(const char_u *const arg, const size_t len) { char *s, *p; static short quick_tab[27] = {0, 0}; /* quick access table */ @@ -4313,6 +4313,8 @@ static int findoption(char_u *arg) } } + assert(len > 0); + /* * Check for name starting with an illegal character. */ @@ -4320,20 +4322,22 @@ static int findoption(char_u *arg) return -1; int opt_idx; - is_term_opt = (arg[0] == 't' && arg[1] == '_'); + is_term_opt = (len > 2 && arg[0] == 't' && arg[1] == '_'); if (is_term_opt) opt_idx = quick_tab[26]; else opt_idx = quick_tab[CharOrdLow(arg[0])]; + // Match full name for (; (s = options[opt_idx].fullname) != NULL; opt_idx++) { - if (STRCMP(arg, s) == 0) /* match full name */ + if (STRNCMP(arg, s, len) == 0 && s[len] == NUL) break; } if (s == NULL && !is_term_opt) { opt_idx = quick_tab[CharOrdLow(arg[0])]; + // Match short name for (; options[opt_idx].fullname != NULL; opt_idx++) { s = options[opt_idx].shortname; - if (s != NULL && STRCMP(arg, s) == 0) /* match short name */ + if (s != NULL && STRNCMP(arg, s, len) == 0 && s[len] == NUL) break; s = NULL; } @@ -4402,6 +4406,15 @@ bool set_tty_option(char *name, char *value) } /* + * Find index for option 'arg'. + * Return -1 if not found. + */ +static int findoption(char_u *arg) +{ + return findoption_len(arg, STRLEN(arg)); +} + +/* * Get the value for an option. * * Returns: |