diff options
author | Bram Moolenaar <Bram@vim.org> | 2013-06-12 17:12:24 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2013-06-12 17:12:24 +0200 |
commit | 2d473ab932b5c46a77715ea507de3990b70d96c1 (patch) | |
tree | 18e5157ad482f7d6047b9081b7ab62a68fe66be1 /src/macros.h | |
parent | 81c40c507c69ab0c3aede3ee14a2ba76c20c4595 (diff) | |
download | vim-git-2d473ab932b5c46a77715ea507de3990b70d96c1.tar.gz |
updated for version 7.3.1175v7.3.1175
Problem: Using isalpha() and isalnum() can be slow.
Solution: Use range checks. (Mike Williams)
Diffstat (limited to 'src/macros.h')
-rw-r--r-- | src/macros.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/macros.h b/src/macros.h index 2c305ce1d..f4a068cfb 100644 --- a/src/macros.h +++ b/src/macros.h @@ -99,6 +99,11 @@ # define MB_TOUPPER(c) TOUPPER_LOC(c) #endif +/* Use our own isdigit() replacement, because on MS-Windows isdigit() returns + * non-zero for superscript 1. Also avoids that isdigit() crashes for numbers + * below 0 and above 255. */ +#define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10) + /* Like isalpha() but reject non-ASCII characters. Can't be used with a * special key (negative value). */ #ifdef EBCDIC @@ -107,17 +112,12 @@ # define ASCII_ISLOWER(c) islower(c) # define ASCII_ISUPPER(c) isupper(c) #else -# define ASCII_ISALPHA(c) ((c) < 0x7f && isalpha(c)) -# define ASCII_ISALNUM(c) ((c) < 0x7f && isalnum(c)) # define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26) # define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26) +# define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c)) +# define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c)) #endif -/* Use our own isdigit() replacement, because on MS-Windows isdigit() returns - * non-zero for superscript 1. Also avoids that isdigit() crashes for numbers - * below 0 and above 255. */ -#define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10) - /* macro version of chartab(). * Only works with values 0-255! * Doesn't work for UTF-8 mode with chars >= 0x80. */ |