|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_TEXT_CHAR_H_
2 #define GENESIS_UTILS_TEXT_CHAR_H_
37 #include <type_traits>
50 constexpr
bool is_ascii(std::true_type , T c) noexcept
60 constexpr
bool is_ascii(std::false_type , T c) noexcept
71 static_assert(0x7F <= CHAR_MAX,
"The compiler is not using ASCII. We cannot work like that!");
72 return is_ascii(std::is_signed<char>{}, c);
81 return c == 0x7F || (c >= 0 && c <= 0x1F);
89 return (c >= 0x00 && c <= 0x08) || (c >= 0x0E && c <= 0x1F) || c == 0x7F;
97 static_assert(
'0' == 48,
"The compiler is not using ASCII. We cannot work like that!");
98 static_assert(
'0' + 9 ==
'9',
"The compiler is not using ASCII. We cannot work like that!");
99 return c >=
'0' && c <=
'9';
107 static_assert(
'A' + 5 ==
'F',
"The compiler is not using ASCII. We cannot work like that!");
108 static_assert(
'a' + 5 ==
'f',
"The compiler is not using ASCII. We cannot work like that!");
109 return is_digit(c) || (c >=
'A' && c <=
'F') || (c >=
'a' && c <=
'f');
117 static_assert(
'a' == 97,
"The compiler is not using ASCII. We cannot work like that!");
118 static_assert(
'a' + 25 ==
'z',
"The compiler is not using ASCII. We cannot work like that!");
119 return c >=
'a' && c <=
'z';
127 static_assert(
'A' == 65,
"The compiler is not using ASCII. We cannot work like that!");
128 static_assert(
'A' + 25 ==
'Z',
"The compiler is not using ASCII. We cannot work like that!");
129 return c >=
'A' && c <=
'Z';
154 static_assert(
'!' + 1 ==
'"',
"The compiler is not using ASCII. We cannot work like that!");
155 static_assert(
':' + 1 ==
';',
"The compiler is not using ASCII. We cannot work like that!");
156 static_assert(
'[' + 1 ==
'\\',
"The compiler is not using ASCII. We cannot work like that!");
157 static_assert(
'{' + 1 ==
'|',
"The compiler is not using ASCII. We cannot work like that!");
159 return (c >=
'!' && c <=
'/') || (c >=
':' && c <=
'@') || (c >=
'[' && c <=
'`') || (c >=
'{' && c <=
'~');
168 return c >=
'!' && c <=
'~';
176 return c ==
'\t' || c ==
' ';
184 return c ==
'\n' || c ==
'\r';
193 return c ==
'\f' || c ==
'\v';
211 return c >=
' ' && c <=
'~';
223 static_assert(
'z' -
'Z' == 0x20,
"The compiler is not using ASCII. We cannot work like that!");
224 return (
'A' <= c && c <=
'Z' ) ? c + 0x20 : c;
232 static_assert(
'z' -
'Z' == 0x20,
"The compiler is not using ASCII. We cannot work like that!");
233 return (
'a' <= c && c <=
'z' ) ? c - 0x20 : c;
268 std::string
char_to_hex(
char c,
bool full =
true );
276 std::string
char_to_hex(
unsigned char c,
bool full =
true );
281 #endif // include guard
constexpr bool is_graph(char c) noexcept
Return whether a char is a character with graphical representation, according to isgraph of the cctyp...
constexpr bool is_control(char c) noexcept
Return whether a char is a control character, excluding white spaces, ASCII-only.
constexpr bool is_ascii(std::true_type, T c) noexcept
Implementation detail for is_ascii(char).
constexpr bool char_match_ci(char c1, char c2) noexcept
Return whether two chars are the same, case insensitive, and ASCII-only.
constexpr bool is_punct(char c) noexcept
Return whether a char is a punctuation mark, according to ispunct of the cctype header,...
constexpr bool is_alnum(char c) noexcept
Return whether a char is a letter (a-z or A-Z) or a digit (0-9), ASCII-only.
constexpr char to_upper(char c) noexcept
Return the upper case version of a letter, ASCII-only.
constexpr bool is_lower(char c) noexcept
Return whether a char is a lower case letter (a-z), ASCII-only.
constexpr bool is_xdigit(char c) noexcept
Return whether a char is a hexadecimal digit (0-9 or A-F or a-f), ASCII-only.
constexpr bool is_space(char c) noexcept
Return whether a char is some form of white space charater, so either space, tab, new line,...
constexpr bool is_other_space(char c) noexcept
Return whether a char is some other white space charater that is neither space, tab,...
constexpr bool is_print(char c) noexcept
Return whether a char is a printable character, according to isprint of the cctype header,...
constexpr bool is_newline(char c) noexcept
Return whether a char is either a new line or a carriage return character.
constexpr bool is_cntrl(char c) noexcept
Return whether a char is a control character, according to iscntrl of the cctype> heade but ASCII-onl...
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
constexpr bool is_digit(char c) noexcept
Return whether a char is a digit (0-9), ASCII-only.
constexpr bool is_blank(char c) noexcept
Return whether a char is either a space or a tab character.
std::string char_to_hex(char c, bool full)
Return the name and hex representation of a char.
constexpr char to_lower(char c) noexcept
Return the lower case version of a letter, ASCII-only.
constexpr bool is_upper(char c) noexcept
Return whether a char is an upper case letter (A-Z), ASCII-only.
constexpr bool is_alpha(char c) noexcept
Return whether a char is a letter (a-z or A-Z), ASCII-only.