4#ifndef TETL_STRING_CHAR_TRAITS_HPP
5#define TETL_STRING_CHAR_TRAITS_HPP
7#include <etl/_compare/strong_ordering.hpp>
8#include <etl/_cstddef/size_t.hpp>
9#include <etl/_cstdint/uint_least_t.hpp>
10#include <etl/_cwchar/wint_t.hpp>
11#include <etl/_ios/typedefs.hpp>
12#include <etl/_strings/cstr.hpp>
18template <
typename CharType,
typename IntType, IntType Eof>
19struct char_traits_base {
20 using char_type = CharType;
21 using int_type = IntType;
22 using off_type =
etl::streamoff;
25 static constexpr auto assign(char_type& a, char_type
const& b)
noexcept ->
void
30 static constexpr auto eq(char_type a, char_type b)
noexcept ->
bool
35 static constexpr auto lt(char_type a, char_type b)
noexcept ->
bool
40 static constexpr auto compare(char_type
const* lhs, char_type
const* rhs, size_t count) ->
int
46 for (size_t i = 0; i < count; ++i) {
47 if (lhs[i] < rhs[i]) {
50 if (lhs[i] > rhs[i]) {
58 static constexpr auto length(char_type
const* str) -> size_t
60 return etl::detail::strlen<char_type, size_t>(str);
63 static constexpr auto find(char_type
const* str, size_t count, char_type
const& token) -> char_type
const*
65 for (size_t i = 0; i < count; ++i) {
66 if (str[i] == token) {
74 static constexpr auto move(char_type* dest, char_type
const* source, size_t count) -> char_type*
76 for (size_t i = 0; i < count; ++i) {
82 static constexpr auto copy(char_type* dest, char_type
const* source, size_t count) -> char_type*
84 for (size_t i = 0; i < count; ++i) {
85 assign(dest[i], source[i]);
90 static constexpr auto assign(char_type* str, size_t count, char_type token) -> char_type*
92 for (size_t i = 0; i < count; ++i) {
93 assign(str[i], token);
98 static constexpr auto to_char_type(int_type c)
noexcept -> char_type
100 return static_cast<char_type>(c);
103 static constexpr auto to_int_type(char_type c)
noexcept -> int_type
105 return static_cast<int_type>(c);
108 static constexpr auto eq_int_type(int_type lhs, int_type rhs)
noexcept ->
bool
113 if (lhs == eof()
and rhs == eof()) {
116 if (lhs == eof()
or rhs == eof()) {
122 static constexpr auto eof()
noexcept -> int_type
127 static constexpr auto not_eof(int_type c)
noexcept -> int_type
129 return !eq_int_type(c, eof()) ? c : 0;
149template <
typename CharT>
155struct char_traits<
char> : detail::char_traits_base<
char,
int, -1> { };
160struct char_traits<
wchar_t> : detail::char_traits_base<
wchar_t, wint_t,
static_cast<wint_t>(WEOF)> { };
165struct char_traits<
char8_t> : detail::char_traits_base<
char8_t,
unsigned,
static_cast<
unsigned>(-1)> { };
170struct char_traits<
char16_t> : detail::char_traits_base<
char16_t, uint_least16_t, uint_least16_t(0xFFFF)> { };
175struct char_traits<
char32_t> : detail::char_traits_base<
char32_t, uint_least32_t, uint_least32_t(0xFFFFFFFF)> { };
Definition adjacent_find.hpp:9
Definition strong_ordering.hpp:15