4#ifndef TETL_FORMAT_ARGUMENT_HPP
5#define TETL_FORMAT_ARGUMENT_HPP
7#include <etl/_algorithm/find.hpp>
8#include <etl/_contracts/check.hpp>
9#include <etl/_format/formatter.hpp>
10#include <etl/_utility/pair.hpp>
12namespace etl::detail {
14inline constexpr auto token_begin =
'{';
15inline constexpr auto token_end =
'}';
17template <
typename ValueT,
typename FormatContext>
18auto format_argument(ValueT
const& val, FormatContext& fc) ->
decltype(fc.out())
20 auto f = formatter<ValueT,
char>{};
21 return f.format(val, fc);
24inline auto split_at_next_argument(
etl::string_view str) ->
etl::
pair<
etl::string_view,
etl::string_view>
26 using size_type =
etl::string_view::size_type;
39template <
typename FormatContext>
40auto format_escaped_sequences(
etl::string_view str, FormatContext& ctx) ->
void
48 auto const escapeStart = openFirst !=
end(str
)
49 && openSec !=
end(str
)
50 && *openSec == token_begin;
54 detail::format_argument(
etl::string_view(first, openFirst), ctx);
59 auto escapeClose = closeFirst !=
end(str
)
60 && closeSec !=
end(str
)
61 && *closeSec == token_end;
65 detail::format_argument(
etl::string_view(openSec, closeFirst + 1), ctx);
66 first = closeFirst + 2;
69 TETL_PRECONDITION(
false);
74 detail::format_argument(
etl::string_view(first,
end(str
)), ctx);
constexpr auto find(InputIt first, InputIt last, T const &value) noexcept -> InputIt
Searches for an element equal to value.
Definition find.hpp:19
constexpr auto end(C &c) -> decltype(c.end())
Returns an iterator to the end (i.e. the element after the last element) of the given container c or ...
Definition end.hpp:15
constexpr auto next(InputIt it, typename iterator_traits< InputIt >::difference_type n=1) -> InputIt
Return the nth successor of iterator it.
Definition next.hpp:15
constexpr auto distance(It first, It last) -> typename iterator_traits< It >::difference_type
Returns the number of hops from first to last.
Definition distance.hpp:17
constexpr auto begin(C &c) -> decltype(c.begin())
Returns an iterator to the beginning of the given container c or array array. These templates rely on...
Definition begin.hpp:21
Definition adjacent_find.hpp:9
constexpr auto make_pair(T1 &&t, T2 &&u) -> pair< decay_t< T1 >, decay_t< T2 > >
Creates a etl::pair object, deducing the target type from the types of arguments.
Definition pair.hpp:167
constexpr basic_string_view() noexcept=default
Default constructor. Constructs an empty basic_string_view. After construction, data() is equal to nu...
constexpr auto substr(size_type pos=0, size_type count=npos) const -> basic_string_view
Returns a view of the substring [pos, pos + rcount), where rcount is the smaller of count and size() ...
Definition basic_string_view.hpp:257
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37