diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2015-04-25 13:34:30 -0300 |
---|---|---|
committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2015-04-25 13:37:44 -0300 |
commit | 0bce4dc54427d05ab320a88f6269a9c1b05ea899 (patch) | |
tree | 4a3aff2749eb0b70b7947ecfc7cd56d56ad4e29d /src/nvim/ascii.h | |
parent | d350d12a00518aa0d9e3a1d49c6815c3398d882f (diff) | |
parent | c96b933acc4d9ec7382d451055e44c85959772b9 (diff) | |
download | rneovim-0bce4dc54427d05ab320a88f6269a9c1b05ea899.tar.gz rneovim-0bce4dc54427d05ab320a88f6269a9c1b05ea899.tar.bz2 rneovim-0bce4dc54427d05ab320a88f6269a9c1b05ea899.zip |
Merge #2486: Replacements for vim_iswhite, VIM_ISDIGIT, vim_isdigit, vim_isxdigit, and vim_isspace
Reviewed-by: Michael Reed <m.reed@mykolab.com>
Diffstat (limited to 'src/nvim/ascii.h')
-rw-r--r-- | src/nvim/ascii.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/nvim/ascii.h b/src/nvim/ascii.h index d9d9eac04d..cc9d1202c2 100644 --- a/src/nvim/ascii.h +++ b/src/nvim/ascii.h @@ -8,6 +8,10 @@ #ifndef NVIM_ASCII_H #define NVIM_ASCII_H +#include <stdbool.h> + +#include "nvim/func_attr.h" + // Definitions of various common control characters. #define CharOrd(x) ((x) < 'a' ? (x) - 'A' : (x) - 'a') @@ -87,4 +91,50 @@ # define PATHSEPSTR "/" #endif +static inline bool ascii_iswhite(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; +static inline bool ascii_isdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; +static inline bool ascii_isxdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; +static inline bool ascii_isspace(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; + +/// Checks if `c` is a space or tab character. +/// +/// @see {ascii_isdigit} +static inline bool ascii_iswhite(int c) +{ + return c == ' ' || c == '\t'; +} + +/// Check whether character is a decimal digit. +/// +/// Library isdigit() function is officially locale-dependent and, for +/// example, returns true for superscript 1 (ยน) in locales where encoding +/// contains it in lower 8 bits. Also avoids crashes in case c is below +/// 0 or above 255: library functions are officially defined as accepting +/// only EOF and unsigned char values (otherwise it is undefined behaviour) +/// what may be used for some optimizations (e.g. simple `return +/// isdigit_table[c];`). +static inline bool ascii_isdigit(int c) +{ + return c >= '0' && c <= '9'; +} + +/// Checks if `c` is a hexadecimal digit, that is, one of 0-9, a-f, A-F. +/// +/// @see {ascii_isdigit} +static inline bool ascii_isxdigit(int c) +{ + return (c >= '0' && c <= '9') + || (c >= 'a' && c <= 'f') + || (c >= 'A' && c <= 'F'); +} + +/// Checks if `c` is a white-space character, that is, +/// one of \f, \n, \r, \t, \v. +/// +/// @see {ascii_isdigit} +static inline bool ascii_isspace(int c) +{ + return (c >= 9 && c <= 13) || c == ' '; +} + #endif /* NVIM_ASCII_H */ |