Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // generate character-based static lookup tables
- // that can be used for character classification,
- // e.g. like in cctype functions (isdigit, isalpha ...)
- struct CharLookupTable
- {
- bool data[256];
- template <unsigned int N>
- constexpr CharLookupTable(const char (&str)[N])
- : data{}
- {
- for (unsigned int i = 0; i < (N - 1); ++i)
- data[static_cast<unsigned char>(str[i])] = true;
- }
- };
- constexpr CharLookupTable digits{"0123456789"};
- constexpr CharLookupTable hexdigits{"0123456789abcdefABCDEF"};
- bool isdigit(char c)
- {
- return digits.data[static_cast<unsigned char>(c)];
- }
- bool ishexdigit(char c)
- {
- return hexdigits.data[static_cast<unsigned char>(c)];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement