char_utils.hpp
Simple functions and tools to manipulate individual characters.
Available Class CharSet - A collection of characters for use in other functions.
Available Functions bool is_whitespace(char test_char) bool is_upper_letter(char test_char) bool is_lower_letter(char test_char) bool is_letter(char test_char) bool is_digit(char test_char) bool is_alphanumeric(char test_char) bool is_idchar(char test_char) bool is_one_of(char test_char, const std::string & char_set) bool is_valid(char test_char ) bool is_valid(char test_char, std::function<bool(char)> fun1, FUNS… funs)
Note
Status: BETA
Typedefs
-
using CharSet = CharSetBase<>
Functions
-
inline bool is_whitespace(char test_char)
-
inline bool is_upper_letter(char test_char)
-
inline bool is_lower_letter(char test_char)
-
inline bool is_letter(char test_char)
-
inline bool is_digit(char test_char)
-
inline bool is_alphanumeric(char test_char)
-
inline bool is_idchar(char test_char)
-
inline bool is_punctuation(char test_char)
-
inline bool is_escape_code(char test_char)
-
static inline bool is_one_of(char test_char, const std::string &char_set)
Determine if a character is in a set of characters (represented as a string)
-
inline bool is_valid(char)
If no functions are provided to is_valid(), always return false as base case.
-
template<typename ...FUNS>
inline bool is_valid(char test_char, std::function<bool(char)> fun1, FUNS... funs) Determine if a character passes any of the test functions provided.
-
inline char ToEscapeChar(char c)
Convert a char after a backslash to its escaped version.
-
template<typename CHAR_T = char, size_t MAX_CHAR = 128>
class CharSetBase - #include <char_utils.hpp>
A char_set is a fast true/false lookup table to identify which ASCII chars are in a set.
Public Functions
-
inline CharSetBase()
-
inline CharSetBase(const char *in_chars)
-
inline CharSetBase &Reset()
-
inline size_t GetMaxChar() const noexcept
-
inline size_t GetSize() const noexcept
Count up the number of characters in the set.
-
inline CharSetBase<CHAR_T, MAX_CHAR> &Set(CHAR_T c)
-
inline CharSetBase<CHAR_T, MAX_CHAR> &Clear(CHAR_T c)
-
inline CharSetBase<CHAR_T, MAX_CHAR> &SetRange(CHAR_T c1, CHAR_T c2)
Set a range of characters INCLUSIVE of c1 and c2.
-
inline CharSetBase<CHAR_T, MAX_CHAR> operator+(const this_t &other) const
-
inline CharSetBase<CHAR_T, MAX_CHAR> operator!() const
-
inline iterator_t begin() const
-
inline iterator_t end() const
-
inline size_t CountMatches(const std::string &str) const
Count the number of matches that occur in a string.
-
inline size_t CountMatches(const std::string &str, size_t start, size_t end) const
Count the number of matches that occur in a sub-string.
Private Types
-
using this_t = CharSetBase<CHAR_T, MAX_CHAR>
Private Members
-
char_set_t char_set = {}
-
class iterator_t
- #include <char_utils.hpp>
Public Functions
-
iterator_t(const iterator_t&) = default
-
iterator_t &operator=(const iterator_t&) = default
-
inline iterator_t &MakeValid()
-
inline bool operator==(const iterator_t &in) const noexcept
-
inline bool operator!=(const iterator_t &in) const noexcept
-
inline bool operator<(const iterator_t &in) const noexcept
-
inline bool operator>(const iterator_t &in) const noexcept
-
inline bool operator<=(const iterator_t &in) const noexcept
-
inline bool operator>=(const iterator_t &in) const noexcept
-
inline iterator_t &operator++()
-
iterator_t(const iterator_t&) = default
-
inline CharSetBase()