di 0.1.0
Loading...
Searching...
No Matches
fixed_string_to_utf8_string_view.h
Go to the documentation of this file.
1#pragma once
2
6#include "di/meta/algorithm.h"
7
8namespace di::container {
9namespace detail {
10 template<container::FixedString literal, size_t... indices>
11 constexpr inline c8 const as_c8_buffer[sizeof...(indices)] = { static_cast<char>(literal.data()[indices])... };
12
13 template<FixedString literal>
14 struct FixedStringToUtf8StringViewFunction {
15 consteval auto operator()() const {
16 return function::unpack<meta::MakeIndexSequence<literal.size()>>(
17 []<usize... indices>(meta::ListV<indices...>) {
18 if constexpr (literal.size() == 0) {
19 return string::StringViewImpl<string::Utf8Encoding> {};
20 } else {
21 auto span = Span { as_c8_buffer<literal, indices...> };
22 DI_ASSERT(container::string::encoding::validate(container::string::Utf8Encoding(), span));
23 return string::StringViewImpl<string::Utf8Encoding> { container::string::encoding::assume_valid,
24 span };
25 }
26 });
27 }
28 };
29}
30
31template<FixedString literal>
32constexpr inline auto fixed_string_to_utf8_string_view = detail::FixedStringToUtf8StringViewFunction<literal> {};
33}
#define DI_ASSERT(...)
Definition assert_bool.h:7
constexpr auto validate
Definition encoding.h:135
constexpr auto assume_valid
Definition encoding.h:236
Definition sequence.h:12
FixedString(char const (&)[size]) -> FixedString< size - 1 >
constexpr auto fixed_string_to_utf8_string_view
Definition fixed_string_to_utf8_string_view.h:32
constexpr auto unpack
Definition unpack.h:24
MakeIntegerSequence< usize, count > MakeIndexSequence
Definition algorithm.h:333
size_t usize
Definition integers.h:33
char8_t c8
Definition char.h:4
Span(Iter, SentOrSize) -> Span< meta::RemoveReference< meta::IteratorReference< Iter > > >