-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlower_wrapper.hh
64 lines (50 loc) · 1.42 KB
/
lower_wrapper.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
// # Lower wrapper and `as_lower()` function
#pragma once
#include "snn-core/array_view.hh"
#include "snn-core/chr/common.hh"
namespace snn::ascii
{
// ## Classes
// ### lower_wrapper
template <typename CharView>
class lower_wrapper final
{
public:
template <character Char>
constexpr explicit lower_wrapper(array_view<Char> s) noexcept
: s_{s}
{
snn_should(s_.none(chr::is_alpha_upper));
}
[[nodiscard]] constexpr auto get() noexcept
{
return s_;
}
[[nodiscard]] constexpr auto get() const noexcept
{
return s_.view();
}
private:
CharView s_;
};
// ## Functions
// ### as_lower
template <character Char>
[[nodiscard]] constexpr auto as_lower(array_view<Char> s) noexcept
{
return lower_wrapper<array_view<Char>>{s};
}
template <typename CharView>
[[nodiscard]] constexpr auto as_lower(not_deduced_t<CharView> s) noexcept
{
return lower_wrapper<CharView>{s};
}
template <same_as<const char> ConstChar, usize N>
[[nodiscard]] constexpr auto as_lower(ConstChar (&string)[N]) noexcept
{
using CharView = array_view<ConstChar>;
return lower_wrapper<CharView>{CharView{string}};
}
}