SeqAn3
parse_condition.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
41 #pragma once
42 
45 
46 // ----------------------------------------------------------------------------
47 // General Purpose Parse Conditions
48 // ----------------------------------------------------------------------------
49 
50 namespace seqan3
51 {
52 
73 template <uint8_t interval_first, uint8_t interval_last>
75  requires interval_first <= interval_last
77 inline detail::is_in_interval_type<interval_first, interval_last> constexpr is_in_interval{};
78 
92 template <alphabet_concept alphabet_t>
93 inline detail::is_in_alphabet_type<alphabet_t> constexpr is_in_alphabet{};
94 
107 template <int char_v>
108 inline detail::is_char_type<char_v> constexpr is_char;
109 
120 inline auto constexpr is_eof = is_char<EOF>;
121 
135 inline auto constexpr is_cntrl = is_in_interval<'\0', static_cast<char>(31)> ||
136  is_char<static_cast<char>(127)>;
137 
150 inline auto constexpr is_print = is_in_interval<' ', '~'> ;
151 
171 inline auto constexpr is_space = is_in_interval<'\t', '\r'> || is_char<' '>;
172 
188 inline auto constexpr is_blank = is_char<'\t'> || is_char<' '>;
189 
208 inline auto constexpr is_graph = is_in_interval<'!', '~'>;
209 
224 inline auto constexpr is_punct = is_in_interval<'!', '/'> ||
225  is_in_interval<':', '@'> ||
226  is_in_interval<'[', '`'> ||
227  is_in_interval<'{', '~'>;
228 
245 inline auto constexpr is_alnum = is_in_interval<'0','9'> ||
246  is_in_interval<'A','Z'> ||
247  is_in_interval<'a','z'>;
248 
264 inline auto constexpr is_alpha = is_in_interval<'A', 'Z'> || is_in_interval<'a', 'z'>;
265 
280 inline auto constexpr is_upper = is_in_interval<'A', 'Z'>;
281 
296 inline auto constexpr is_lower = is_in_interval<'a', 'z'>;
297 
312 inline auto constexpr is_digit = is_in_interval<'0', '9'>;
313 
330 inline auto constexpr is_xdigit = is_in_interval<'0', '9'> ||
331  is_in_interval<'A', 'F'> ||
332  is_in_interval<'a', 'f'>;
334 
349 template <typename condition_type>
351 {
353  static condition_type constexpr cond{};
354 
356  constexpr parse_asserter(condition_type const &) noexcept {}
357 
375  template <char_adaptation_concept char_type>
376  void operator()(char_type const c) const
377  {
378  if (!std::invoke(cond, c))
379  {
380  using namespace std::literals;
381  // I can not assure that all parameters are convertible to c.
382  throw parse_error{"Parsed value <"s + detail::make_printable(to_char(c)) +
383  "> which does not fulfill the following condition: "s +
384  cond.message()};
385  }
386  }
387 };
388 
987 } // namespace seqan3
auto constexpr is_print
Checks whether c is a printable character.
Definition: parse_condition.hpp:150
auto constexpr is_alnum
Checks whether c is a alphanumeric character.
Definition: parse_condition.hpp:245
A condition checker, that wraps a parse condition and throws a specified exception if the condition w...
Definition: parse_condition.hpp:350
auto constexpr is_upper
Checks whether c is a upper case character.
Definition: parse_condition.hpp:280
auto constexpr is_blank
Checks whether c is a blank character.
Definition: parse_condition.hpp:188
auto constexpr is_graph
Checks whether c is a graphic character.
Definition: parse_condition.hpp:208
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
auto constexpr is_digit
Checks whether c is a digital character.
Definition: parse_condition.hpp:312
detail::is_in_alphabet_type< alphabet_t > constexpr is_in_alphabet
Checks whether a given letter is valid for the specified seqan3::alphabet_concept.
Definition: parse_condition.hpp:93
constexpr parse_asserter(condition_type const &) noexcept
Allow type deduction from constructor argument.
Definition: parse_condition.hpp:356
auto constexpr is_cntrl
Checks whether c is a control character.
Definition: parse_condition.hpp:135
Thrown if there is a parse error, such as reading an unexpected character from an input stream...
Definition: exception.hpp:70
auto constexpr is_alpha
Checks whether c is a alphabetical character.
Definition: parse_condition.hpp:264
Provides parse conditions for tokenization.
static condition_type constexpr cond
Stores an instance of the stateless condition.
Definition: parse_condition.hpp:353
auto constexpr is_eof
Checks whether a given letter is equal to the EOF constant defined in <cstdio>.
Definition: parse_condition.hpp:120
auto constexpr is_space
Checks whether c is a space character.
Definition: parse_condition.hpp:171
auto constexpr is_punct
Checks whether c is a punctuation character.
Definition: parse_condition.hpp:224
Core alphabet concept and free function/metafunction wrappers.
auto constexpr is_xdigit
Checks whether c is a hexadecimal character.
Definition: parse_condition.hpp:330
detail::is_char_type< char_v > constexpr is_char
Checks whether a given letter is the same as the template non-type argument.
Definition: parse_condition.hpp:108
void operator()(char_type const c) const
Checks if the given character satisfies the associated parse condition.
Definition: parse_condition.hpp:376
detail::is_in_interval_type< interval_first, interval_last > constexpr is_in_interval
Checks whether a given letter is in the specified interval.
Definition: parse_condition.hpp:77
constexpr underlying_char_t< alphabet_type > to_char(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::alphabet_concept::to_char() that delegates to a member function.
Definition: member_exposure.hpp:165
auto constexpr is_lower
Checks whether c is a lower case character.
Definition: parse_condition.hpp:296