SeqAn3  3.0.0
The Modern C++ library for sequence analysis.
transform.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <array>
16 #include <cmath>
17 
20 
21 namespace seqan3::detail
22 {
23 
26 template <typename char_type>
27 inline std::array<char_type, detail::size_in_values_v<char_type>> constexpr to_lower_table
28 {
29  [] () constexpr
30  {
32 
33  for (size_t i = 0; i < detail::size_in_values_v<char_type>; ++i)
34  ret[i] = i;
35 
36  for (size_t i = char_type{'A'}; i <= char_type{'Z'}; ++i)
37  ret[i] = ret[i] - char_type{'A'} + char_type{'a'};
38 
39  return ret;
40  } ()
41 };
42 
45 template <typename char_type>
46 inline std::array<char_type, detail::size_in_values_v<char_type>> constexpr to_upper_table
47 {
48  [] () constexpr
49  {
51 
52  for (size_t i = 0; i < detail::size_in_values_v<char_type>; ++i)
53  ret[i] = i;
54 
55  for (size_t i = char_type{'a'}; i <= char_type{'z'}; ++i)
56  ret[i] = ret[i] - char_type{'a'} + char_type{'A'};
57 
58  return ret;
59  } ()
60 };
61 
62 } // namespace seqan3::detail
63 
64 namespace seqan3
65 {
66 
81 template <Char char_type>
82 constexpr char_type to_lower(char_type const c) noexcept
83 {
85  return detail::to_lower_table<char_type>[static_cast<u_t>(c)];
86 }
87 
97 template <Char char_type>
98 constexpr char_type to_upper(char_type const c) noexcept
99 {
101  return detail::to_upper_table<char_type>[static_cast<u_t>(c)];
102 }
104 
105 } // namespace seqan3
Provides concepts for core language types and relations that don&#39;t have concepts in C++20 (yet)...
Provides metaprogramming utilities for integer types.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:35
constexpr char_type to_upper(char_type const c) noexcept
Converts &#39;a&#39;-&#39;z&#39; to &#39;A&#39;-&#39;Z&#39; respectively; other characters are returned as is.
Definition: transform.hpp:98
constexpr char_type to_lower(char_type const c) noexcept
Converts &#39;A&#39;-&#39;Z&#39; to &#39;a&#39;-&#39;z&#39; respectively; other characters are returned as is.
Definition: transform.hpp:82