Created
July 22, 2023 11:58
-
-
Save dbremner/5de2ef59196968baf032a17b70e438aa to your computer and use it in GitHub Desktop.
These avoid issues with out of range values for ctype.h functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CHAR_PREDICATES_HPP | |
#define CHAR_PREDICATES_HPP | |
[[nodiscard]] static inline bool | |
is_digit(int ch) | |
{ | |
return ((ch >= '0') && (ch <= '9')); | |
} | |
[[nodiscard]] static inline bool | |
is_alpha(int ch) | |
{ | |
const bool lower = (ch >= 'a') && (ch <= 'z'); | |
const bool upper = (ch >= 'A') && (ch <= 'Z'); | |
const bool either = lower || upper; | |
return either; | |
} | |
[[nodiscard]] static inline bool | |
is_ident(int ch) | |
{ | |
const bool any = (is_digit(ch)) || (is_alpha(ch)) || (ch == '_'); | |
return any; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment