3#ifndef TETL_STRING_CHAR_TRAITS_HPP
4#define TETL_STRING_CHAR_TRAITS_HPP
17template <
typename CharType,
typename IntType, IntType Eof>
18struct char_traits_base {
19 using char_type = CharType;
20 using int_type = IntType;
22 using comparison_category = etl::strong_ordering;
24 static constexpr auto assign(char_type& a, char_type
const& b)
noexcept ->
void {
a =
b; }
26 static constexpr auto eq(char_type a, char_type b)
noexcept ->
bool {
return a ==
b; }
28 static constexpr auto lt(char_type a, char_type b)
noexcept ->
bool {
return a <
b; }
30 static constexpr auto compare(char_type
const* lhs, char_type
const* rhs,
size_t count) ->
int
36 for (
size_t i = 0; i <
count; ++i) {
37 if (lhs[i] < rhs[i]) {
40 if (lhs[i] > rhs[i]) {
48 static constexpr auto length(char_type
const* str) ->
size_t {
return etl::detail::strlen<char_type, size_t>(str); }
50 static constexpr auto find(char_type
const* str,
size_t count, char_type
const& token) -> char_type
const*
52 for (
size_t i = 0; i <
count; ++i) {
53 if (str[i] == token) {
61 static constexpr auto move(char_type* dest, char_type
const* source,
size_t count) -> char_type*
63 for (
size_t i = 0; i <
count; ++i) {
69 static constexpr auto copy(char_type* dest, char_type
const* source,
size_t count) -> char_type*
71 for (
size_t i = 0; i <
count; ++i) {
72 assign(dest[i], source[i]);
77 static constexpr auto assign(char_type* str,
size_t count, char_type token) -> char_type*
79 for (
size_t i = 0; i <
count; ++i) {
80 assign(str[i], token);
85 static constexpr auto to_char_type(int_type c)
noexcept -> char_type {
return static_cast<char_type
>(c); }
87 static constexpr auto to_int_type(char_type c)
noexcept -> int_type {
return static_cast<int_type
>(c); }
89 static constexpr auto eq_int_type(int_type lhs, int_type rhs)
noexcept ->
bool
94 if (lhs == eof() and rhs == eof()) {
97 if (lhs == eof() or rhs == eof()) {
103 static constexpr auto eof() noexcept -> int_type {
return Eof; }
105 static constexpr auto not_eof(int_type c)
noexcept -> int_type {
return !eq_int_type(c, eof()) ? c : 0; }
124template <
typename CharT>
130struct char_traits<char> : detail::char_traits_base<char, int, -1> { };
135struct char_traits<wchar_t> : detail::char_traits_base<wchar_t, wint_t, static_cast<wint_t>(WEOF)> { };
140struct char_traits<char8_t> : detail::char_traits_base<char8_t, unsigned, static_cast<unsigned>(-1)> { };
145struct char_traits<char16_t> : detail::char_traits_base<char16_t, uint_least16_t, uint_least16_t(0xFFFF)> { };
150struct char_traits<char32_t> : detail::char_traits_base<char32_t, uint_least32_t, uint_least32_t(0xFFFFFFFF)> { };
constexpr auto count(InputIt first, InputIt last, T const &value) -> typename iterator_traits< InputIt >::difference_type
Returns the number of elements in the range [first, last) satisfying specific criteria....
Definition count.hpp:21
@ a
Definition mcp23017.hpp:14
@ b
Definition mcp23017.hpp:15
Definition adjacent_find.hpp:8
long streamoff
Definition typedefs.hpp:11
The char_traits class is a traits class template that abstracts basic character and string operations...
Definition char_traits.hpp:125