Character classification

Character classification similar to the one provided in <cctype>. The difference is that functions here:

  • Don’t implicitly account for the locale.

  • Are a few times faster than the standard ones, because they don’t account for the locale and can be efficiently inlined.

  • Return bool as expected.

  • Don’t try to handle the EOF character.

Reference

namespace ac

Functions

inline bool is_digit(char c) noexcept

Checks if c is a decimal digit.

inline bool is_lower(char c) noexcept

Checks if c is a lowercase letter.

inline bool is_upper(char c) noexcept

Checks if c is an uppercase letter.

inline bool is_alpha(char c) noexcept

Checks if c is an alphabetic character (a letter).

inline bool is_alphanumeric(char c) noexcept

Checks if c is an alphabetic character or a decimal digit.

inline bool is_space(char c) noexcept

Checks if c is a whitespace character, that is one of:

  • space (0x20, ‘ ‘)

  • form feed (0x0c, ‘\f’)

  • line feed (0x0a, ‘\n’)

  • carriage return (0x0d, ‘\r’)

  • horizontal tab (0x09, ‘\t’)

  • vertical tab (0x0b, ‘\v’)

Source code

Tests