diff options
Diffstat (limited to 'src/charset.c')
-rw-r--r-- | src/charset.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/charset.c b/src/charset.c index 3eb5b5805..cff62e185 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1776,25 +1776,30 @@ vim_isblankline(char_u *lbuf) * If "what" contains STR2NR_HEX recognize hex numbers * If "what" contains STR2NR_FORCE always assume bin/oct/hex. * If maxlen > 0, check at a maximum maxlen chars. + * If strict is TRUE, check the number strictly. return *len = 0 if fail. */ void vim_str2nr( char_u *start, - int *prep, /* return: type of number 0 = decimal, 'x' - or 'X' is hex, '0' = octal, 'b' or 'B' - is bin */ - int *len, /* return: detected length of number */ - int what, /* what numbers to recognize */ - varnumber_T *nptr, /* return: signed result */ - uvarnumber_T *unptr, /* return: unsigned result */ - int maxlen) /* max length of string to check */ + int *prep, // return: type of number 0 = decimal, 'x' + // or 'X' is hex, '0' = octal, 'b' or 'B' + // is bin + int *len, // return: detected length of number + int what, // what numbers to recognize + varnumber_T *nptr, // return: signed result + uvarnumber_T *unptr, // return: unsigned result + int maxlen, // max length of string to check + int strict) // check strictly { char_u *ptr = start; - int pre = 0; /* default is decimal */ + int pre = 0; // default is decimal int negative = FALSE; uvarnumber_T un = 0; int n; + if (len != NULL) + *len = 0; + if (ptr[0] == '-') { negative = TRUE; @@ -1836,9 +1841,7 @@ vim_str2nr( } } - /* - * Do the string-to-numeric conversion "manually" to avoid sscanf quirks. - */ + // Do the conversion manually to avoid sscanf() quirks. n = 1; if (pre == 'B' || pre == 'b' || what == STR2NR_BIN + STR2NR_FORCE) { @@ -1907,6 +1910,10 @@ vim_str2nr( break; } } + // Check for an alpha-numeric character immediately following, that is + // most likely a typo. + if (strict && n - 1 != maxlen && ASCII_ISALNUM(*ptr)) + return; if (prep != NULL) *prep = pre; |