SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
transform.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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 
19 
20 namespace seqan3::detail
21 {
22 
23 // clang-format off
26 template <typename char_type>
27 inline constexpr std::array<char_type, detail::size_in_values_v<char_type>> 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 constexpr std::array<char_type, detail::size_in_values_v<char_type>> 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 // clang-format on
62 
63 } // namespace seqan3::detail
64 
65 namespace seqan3
66 {
67 
82 template <builtin_character char_type>
83 constexpr char_type to_lower(char_type const c) noexcept
84 {
86  return detail::to_lower_table<char_type>[static_cast<u_t>(c)];
87 }
88 
98 template <builtin_character char_type>
99 constexpr char_type to_upper(char_type const c) noexcept
100 {
102  return detail::to_upper_table<char_type>[static_cast<u_t>(c)];
103 }
105 
106 } // namespace seqan3
Provides metaprogramming utilities for integer types.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
constexpr char_type to_upper(char_type const c) noexcept
Converts 'a'-'z' to 'A'-'Z' respectively; other characters are returned as is.
Definition: transform.hpp:99
constexpr char_type to_lower(char_type const c) noexcept
Converts 'A'-'Z' to 'a'-'z' respectively; other characters are returned as is.
Definition: transform.hpp:83
Provides concepts that do not have equivalents in C++20.