SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
builtin_character operations

Provides various operations on character types. More...

+ Collaboration diagram for builtin_character operations:

Char predicates

Char predicates are function like objects that can be used to check if a character c fulfills certain constraints. SeqAn implements all predicates also available in the standard library and some more.

Disjunction and Negation

In contrast to the standard library (where the checks are implemented as functions), the functors in SeqAn can be joined efficiently, maintaining constant-time evaluation independent of the number of checks. Functors can be combined with the ||-operator or negated via the !-operator:

int main()
{
char chr{'1'};
auto constexpr my_cond = seqan3::is_char<'%'> || seqan3::is_digit;
bool is_percent = my_cond(chr); // is_percent == true
}

Defining complex combinations and using them in e.g. input/output can increase speed significantly over checking multiple functions: we measured speed-ups of 10x for a single check and speed-ups of over 20x for complex combinations.

Custom predicates

Standard library predicates

SeqAn offers the 12 predicates exactly as defined in the standard library except that we have introduced an underscore in the name to be consistent with our other naming.

The following table lists the predefined character predicates and which constraints are associated with them.

ASCII values characters

is_cntrl

is_print

is_space

is_blank

is_graph

is_punct

is_alnum

is_alpha

is_upper

is_lower

is_digit

is_xdigit

decimal hexadecimal octal
0–8 \x0\x8 \0\10 control codes (NUL, etc.) ≠0 0 0 0 0 0 0 0 0 0 0 0
9 \x9 \11 tab (\t) ≠0 0 ≠0 ≠0 0 0 0 0 0 0 0 0
10–13 \xA\xD \12\15 whitespaces (\n, \v, \f, \r) ≠0 0 ≠0 0 0 0 0 0 0 0 0 0
14–31 \xE\x1F \16\37 control codes ≠0 0 0 0 0 0 0 0 0 0 0 0
32 \x20 \40 space 0 ≠0 ≠0 ≠0 0 0 0 0 0 0 0 0
33–47 \x21\x2F \41\57 !"#$%&'()*+,-./ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
48–57 \x30\x39 \60\71 0123456789 0 ≠0 0 0 ≠0 0 ≠0 0 0 0 ≠0 ≠0
58–64 \x3A\x40 \72\100 :;<=>?@ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
65–70 \x41\x46 \101\106 ABCDEF 0 ≠0 0 0 ≠0 0 ≠0 ≠0 ≠0 0 0 ≠0
71–90 \x47\x5A \107\132 GHIJKLMNOP
QRSTUVWXYZ
0 ≠0 0 0 ≠0 0 ≠0 ≠0 ≠0 0 0 0
91–96 \x5B\x60 \133\140 []^_` 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
97–102 \x61\x66 \141\146 abcdef 0 ≠0 0 0 ≠0 0 ≠0 ≠0 0 ≠0 0 ≠0
103–122 \x67\x7A \147\172 ghijklmnop
qrstuvwxyz
0 ≠0 0 0 ≠0 0 ≠0 ≠0 0 ≠0 0 0
123–126 \x7B\x7E \172\176 {|}~ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
127 \x7F \177 backspace character (DEL) ≠0 0 0 0 0 0 0 0 0 0 0 0


template<uint8_t interval_first, uint8_t interval_last>
constexpr auto seqan3::is_in_interval
 Checks whether a given letter is in the specified interval. More...
 
template<alphabet alphabet_t>
constexpr auto seqan3::is_in_alphabet
 Checks whether a given letter is valid for the specified seqan3::alphabet. More...
 
template<int char_v>
constexpr auto seqan3::is_char
 Checks whether a given letter is the same as the template non-type argument. More...
 
auto constexpr seqan3::is_cntrl
 Checks whether c is a control character. More...
 
auto constexpr seqan3::is_print = is_in_interval<' ', '~'>
 Checks whether c is a printable character. More...
 
auto constexpr seqan3::is_space = is_in_interval<'\t', '\r'> || is_char<' '>
 Checks whether c is a space character. More...
 
auto constexpr seqan3::is_blank = is_char<'\t'> || is_char<' '>
 Checks whether c is a blank character. More...
 
auto constexpr seqan3::is_graph = is_in_interval<'!', '~'>
 Checks whether c is a graphic character. More...
 
auto constexpr seqan3::is_punct
 Checks whether c is a punctuation character. More...
 
auto constexpr seqan3::is_alnum
 Checks whether c is a alphanumeric character. More...
 
auto constexpr seqan3::is_alpha = is_in_interval<'A', 'Z'> || is_in_interval<'a', 'z'>
 Checks whether c is a alphabetical character. More...
 
auto constexpr seqan3::is_upper = is_in_interval<'A', 'Z'>
 Checks whether c is a upper case character. More...
 
auto constexpr seqan3::is_lower = is_in_interval<'a', 'z'>
 Checks whether c is a lower case character. More...
 
auto constexpr seqan3::is_digit = is_in_interval<'0', '9'>
 Checks whether c is a digital character. More...
 
auto constexpr seqan3::is_xdigit
 Checks whether c is a hexadecimal character. More...
 
auto constexpr seqan3::is_eof = is_char<EOF>
 Checks whether a given letter is equal to the EOF constant defined in <cstdio>. More...
 

Detailed Description

Provides various operations on character types.

Variable Documentation

◆ is_alnum

auto constexpr seqan3::is_alnum
inline
Initial value:
= is_in_interval<'0','9'> ||
is_in_interval<'A','Z'> ||
is_in_interval<'a','z'>

Checks whether c is a alphanumeric character.

This function like object can be used to check if a character c is a alphanumeric character. For the standard ASCII character set, the following characters are alphanumeric characters:

  • digits (0123456789)
  • uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
  • lowercase letters (abcdefghijklmnopqrstuvwxyz)

Example

seqan3::is_alnum('9'); // returns true.

◆ is_alpha

auto constexpr seqan3::is_alpha = is_in_interval<'A', 'Z'> || is_in_interval<'a', 'z'>
inline

Checks whether c is a alphabetical character.

This function like object can be used to check if a character c is a alphabetical character. For the standard ASCII character set, the following characters are alphabetical characters:

  • uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
  • lowercase letters (abcdefghijklmnopqrstuvwxyz)

Example

seqan3::is_alpha('z'); // returns true.

◆ is_blank

auto constexpr seqan3::is_blank = is_char<'\t'> || is_char<' '>
inline

Checks whether c is a blank character.

This function like object can be used to check if a character c is a blank character. For the standard ASCII character set, the following characters are blank characters:

  • horizontal tab ('\t')
  • space (' ')

Example

seqan3::is_blank('\t'); // returns true.

◆ is_char

template<int char_v>
constexpr auto seqan3::is_char
inline

Checks whether a given letter is the same as the template non-type argument.

Template Parameters
char_vThe letter to compare against.

This function like object returns true if the argument is the same as the template argument, false otherwise.

Example

int main()
{
seqan3::is_char<'C'>('C'); // returns true
auto constexpr my_check = seqan3::is_char<'C'>;
my_check('c'); // returns false, because case is different
}

◆ is_cntrl

auto constexpr seqan3::is_cntrl
inline
Initial value:
= is_in_interval<'\0', static_cast<char>(31)> ||
is_char<static_cast<char>(127)>
constexpr auto is_char
Checks whether a given letter is the same as the template non-type argument.
Definition: predicate.hpp:83

Checks whether c is a control character.

This function like object can be used to check if a character c is a control character. For the standard ASCII character set, control characters are those between ASCII codes 0x00 (NUL) and 0x1f (US) and 0x7f (DEL).

Example

seqan3::is_cntrl('\0'); // returns true.

◆ is_digit

auto constexpr seqan3::is_digit = is_in_interval<'0', '9'>
inline

Checks whether c is a digital character.

This function like object can be used to check if a character c is a digital character. For the standard ASCII character set, the following characters are digital characters:

  • digits (0123456789)

Example

seqan3::is_digit('1'); // returns true.

◆ is_eof

auto constexpr seqan3::is_eof = is_char<EOF>
inline

Checks whether a given letter is equal to the EOF constant defined in <cstdio>.

This function like object returns true if the argument is equal to EOF, false otherwise.

Example

seqan3::is_eof(EOF); // returns true
seqan3::is_eof('C'); // returns false

◆ is_graph

auto constexpr seqan3::is_graph = is_in_interval<'!', '~'>
inline

Checks whether c is a graphic character.

This function like object can be used to check if a character c is a graphic (has a graphical representation) character. For the standard ASCII character set, the following characters are graphic characters:

  • digits (0123456789)
  • uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
  • lowercase letters (abcdefghijklmnopqrstuvwxyz)
  • punctuation characters (!"#$%&'()*+,-./:;<=>?@[]^_`{|}~)

Example

seqan3::is_graph('%'); // returns true.

◆ is_in_alphabet

template<alphabet alphabet_t>
constexpr auto seqan3::is_in_alphabet
inline

Checks whether a given letter is valid for the specified seqan3::alphabet.

Template Parameters
alphabet_tThe alphabet to check; must model seqan3::alphabet.

This function like object returns true for all characters of the alphabet, false otherwise. The actual check being performed is whether assigning and then reading a letter results in the original input (but case is ignored).

Example

int main()
{
seqan3::is_in_alphabet<seqan3::dna4>('C'); // returns true
auto constexpr my_check = seqan3::is_in_alphabet<seqan3::dna4>;
my_check('U'); // returns false, because it comes out as 'T'
}

◆ is_in_interval

template<uint8_t interval_first, uint8_t interval_last>
constexpr auto seqan3::is_in_interval
inline

Checks whether a given letter is in the specified interval.

Template Parameters
interval_firstThe first character for which to return true.
interval_lastThe last character (inclusive) for which to return true.

This function like object returns true for all characters in the given range, false otherwise.

Example

int main()
{
seqan3::is_in_interval<'A', 'G'>('C'); // returns true
auto constexpr my_check = seqan3::is_in_interval<'A', 'G'>;
my_check('H'); // returns false
}

◆ is_lower

auto constexpr seqan3::is_lower = is_in_interval<'a', 'z'>
inline

Checks whether c is a lower case character.

This function like object can be used to check if a character c is a lower case character. For the standard ASCII character set, the following characters are lower case characters:

  • lowercase letters (abcdefghijklmnopqrstuvwxyz)

Example

seqan3::is_lower('a'); // returns true.

◆ is_print

auto constexpr seqan3::is_print = is_in_interval<' ', '~'>
inline

Checks whether c is a printable character.

This function like object can be used to check if a character c is a printable character. For the standard ASCII character set, printable characters are those between ASCII codes 0x20 (space) and 0x7E (~).

Example

seqan3::is_print(' '); // returns true.

◆ is_punct

auto constexpr seqan3::is_punct
inline
Initial value:
= is_in_interval<'!', '/'> ||
is_in_interval<':', '@'> ||
is_in_interval<'[', '`'> ||
is_in_interval<'{', '~'>
constexpr auto is_in_interval
Checks whether a given letter is in the specified interval.
Definition: predicate.hpp:50

Checks whether c is a punctuation character.

This function like object can be used to check if a character c is a punctuation character. For the standard ASCII character set, the following characters are punctuation characters:

  • punctuation characters (!"#$%&'()*+,-./:;<=>?@[]^_`{|}~)

Example

seqan3::is_punct(':'); // returns true.

◆ is_space

auto constexpr seqan3::is_space = is_in_interval<'\t', '\r'> || is_char<' '>
inline

Checks whether c is a space character.

This function like object can be used to check if a character c is a space character. For the standard ASCII character set, the following characters are space characters:

  • horizontal tab ('\t')
  • line feed ('\n')
  • vertical tab ('\v')
  • from feed ('\f')
  • carriage return ('\r')
  • space (' ')

Example

seqan3::is_space('\n'); // returns true.

◆ is_upper

auto constexpr seqan3::is_upper = is_in_interval<'A', 'Z'>
inline

Checks whether c is a upper case character.

This function like object can be used to check if a character c is a upper case character. For the standard ASCII character set, the following characters are upper case characters:

  • uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)

Example

seqan3::is_upper('K'); // returns true.

◆ is_xdigit

auto constexpr seqan3::is_xdigit
inline
Initial value:
= is_in_interval<'0', '9'> ||
is_in_interval<'A', 'F'> ||
is_in_interval<'a', 'f'>

Checks whether c is a hexadecimal character.

This function like object can be used to check if a character c is a hexadecimal character. For the standard ASCII character set, the following characters are hexadecimal characters:

  • digits (0123456789)
  • uppercase letters (ABCDEF)
  • lowercase letters (abcdef)

Example

seqan3::is_xdigit('e'); // returns true.