4#ifndef TETL_FORMAT_FORMATTER_HPP
5#define TETL_FORMAT_FORMATTER_HPP
7#include <etl/_algorithm/copy.hpp>
8#include <etl/_cstring/strlen.hpp>
9#include <etl/_format/basic_format_context.hpp>
10#include <etl/_string/basic_inplace_string.hpp>
11#include <etl/_string_view/basic_string_view.hpp>
12#include <etl/_strings/from_integer.hpp>
19template <
typename T,
typename CharT =
char>
23 auto operator=(formatter
const& other) -> formatter =
delete;
28struct formatter<
char,
char> {
29 template <
typename FormatContext>
30 constexpr auto format(
char val, FormatContext& fc) ->
decltype(fc.out())
39struct formatter<
char const*,
char> {
40 template <
typename FormatContext>
41 constexpr auto format(
char const* val, FormatContext& fc) ->
decltype(fc.out())
47template <
etl::size_t N>
48struct formatter<
char[N],
char> {
49 template <
typename FormatContext>
50 constexpr auto format(
char const* val, FormatContext& fc) ->
decltype(fc.out())
52 return etl::copy(val, val + N, fc.out());
57struct formatter<
etl::string_view,
char> {
58 template <
typename FormatContext>
59 constexpr auto format(
etl::string_view str, FormatContext& fc) ->
decltype(fc.out())
65template <
etl::size_t Capacity>
66struct formatter<
etl::inplace_string<Capacity>,
char> {
67 template <
typename FormatContext>
68 constexpr auto format(
etl::inplace_string<Capacity>
const& str, FormatContext& fc) ->
decltype(fc.out())
70 return formatter<
etl::string_view>().format(str, fc);
75template <
typename Integer,
typename FormatContext>
76constexpr auto integer_format(Integer v, FormatContext& fc) ->
decltype(fc.out())
82 return formatter<string_view>().format(str, fc);
84 return formatter<string_view>().format(
"", fc);
89struct formatter<
short,
char> {
90 template <
typename FormatContext>
91 constexpr auto format(
short v, FormatContext& fc) ->
decltype(fc.out())
93 return detail::integer_format(v, fc);
98struct formatter<
int,
char> {
99 template <
typename FormatContext>
100 constexpr auto format(
int v, FormatContext& fc) ->
decltype(fc.out())
102 return detail::integer_format(v, fc);
107struct formatter<
long,
char> {
108 template <
typename FormatContext>
109 constexpr auto format(
long v, FormatContext& fc) ->
decltype(fc.out())
111 return detail::integer_format(v, fc);
116struct formatter<
long long,
char> {
117 template <
typename FormatContext>
118 constexpr auto format(
long long v, FormatContext& fc) ->
decltype(fc.out())
120 return detail::integer_format(v, fc);
125struct formatter<
unsigned short,
char> {
126 template <
typename FormatContext>
127 constexpr auto format(
unsigned short v, FormatContext& fc) ->
decltype(fc.out())
129 return detail::integer_format(v, fc);
134struct formatter<
unsigned,
char> {
135 template <
typename FormatContext>
136 constexpr auto format(
int v, FormatContext& fc) ->
decltype(fc.out())
138 return detail::integer_format(v, fc);
143struct formatter<
unsigned long,
char> {
144 template <
typename FormatContext>
145 constexpr auto format(
unsigned long v, FormatContext& fc) ->
decltype(fc.out())
147 return detail::integer_format(v, fc);
152struct formatter<
unsigned long long,
char> {
153 template <
typename FormatContext>
154 constexpr auto format(
unsigned long long v, FormatContext& fc) ->
decltype(fc.out())
156 return detail::integer_format(v, fc);
constexpr auto strlen(char const *str) -> etl::size_t
Returns the length of the C string str.
Definition strlen.hpp:14
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 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
constexpr auto begin(T(&array)[N]) noexcept -> T *
Definition begin.hpp:35
from_integer_error
Definition from_integer.hpp:20
Definition adjacent_find.hpp:9
constexpr basic_string_view(Char const *str)
Constructs a view of the null-terminated character string pointed to by s, not including the terminat...
Definition basic_string_view.hpp:75