SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
transform.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 
25 template <typename char_type>
26 inline std::array<char_type, detail::size_in_values_v<char_type>> constexpr to_lower_table
27 {
28  [] () constexpr
29  {
31 
32  for (size_t i = 0; i < detail::size_in_values_v<char_type>; ++i)
33  ret[i] = i;
34 
35  for (size_t i = char_type{'A'}; i <= char_type{'Z'}; ++i)
36  ret[i] = ret[i] - char_type{'A'} + char_type{'a'};
37 
38  return ret;
39  } ()
40 };
41 
44 template <typename char_type>
45 inline std::array<char_type, detail::size_in_values_v<char_type>> constexpr to_upper_table
46 {
47  [] () constexpr
48  {
50 
51  for (size_t i = 0; i < detail::size_in_values_v<char_type>; ++i)
52  ret[i] = i;
53 
54  for (size_t i = char_type{'a'}; i <= char_type{'z'}; ++i)
55  ret[i] = ret[i] - char_type{'a'} + char_type{'A'};
56 
57  return ret;
58  } ()
59 };
60 
61 } // namespace seqan3::detail
62 
63 namespace seqan3
64 {
65 
80 template <builtin_character char_type>
81 constexpr char_type to_lower(char_type const c) noexcept
82 {
84  return detail::to_lower_table<char_type>[static_cast<u_t>(c)];
85 }
86 
96 template <builtin_character char_type>
97 constexpr char_type to_upper(char_type const c) noexcept
98 {
100  return detail::to_upper_table<char_type>[static_cast<u_t>(c)];
101 }
103 
104 } // namespace seqan3
core_language.hpp
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
array
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::to_upper
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:97
int_types.hpp
Provides metaprogramming utilities for integer types.
seqan3::to_lower
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:81
std::make_unsigned_t