4#ifndef TETL_FORMAT_FORMAT_TO_HPP
5#define TETL_FORMAT_FORMAT_TO_HPP
7#include <etl/_format/argument.hpp>
8#include <etl/_format/basic_format_context.hpp>
9#include <etl/_type_traits/remove_cvref.hpp>
10#include <etl/_vector/static_vector.hpp>
13template <
typename Iter>
20template <
typename OutputIt,
typename... Args>
21auto format_to(OutputIt out,
etl::string_view fmt, Args
const&... args) -> OutputIt
23 auto ctx = format_context{out};
26 auto const slices = detail::split_at_next_argument(fmt);
27 detail::format_escaped_sequences(slices.first, ctx);
31 auto rest = slices.second;
36 detail::format_argument(args, ctx);
39 auto const restSlices = detail::split_at_next_argument(rest);
40 detail::format_escaped_sequences(restSlices.first, ctx);
43 rest
= restSlices.second;
47 if (
auto const trailing = detail::split_at_next_argument(rest); !trailing.first
.empty()) {
48 detail::format_escaped_sequences(trailing.first, ctx);
49 TETL_ASSERT(trailing.second.empty());
59template <
typename Out>
69template <
typename OutputIter,
typename... Args>
70auto format_to_n(OutputIter out, diff_t<OutputIter> n,
etl::string_view fmt, Args
const&... args)
73 etl::ignore_unused(n);
78 auto writeChar = [&result](
auto ch) {
83 auto varStart =
etl::size_t{};
84 for (
decltype(fmt)::size_type i{}; i < fmt
.size(); ++i) {
87 if ((fmt
.size() > i + 1) && (fmt
[i + 1
] ==
'{')) {
98 if ((fmt
.size() > i + 1) && (fmt
[i + 1
] ==
'}')) {
104 indices.push_back(varStart);
112 if (indices.size() > 0) {
113 [[maybe_unused]]
auto replaceCharAt = [n](
auto output,
auto pos,
char val) {
114 etl::ignore_unused(n);
119 [[maybe_unused]]
typename decltype(indices)::size_type i{};
120 (replaceCharAt(out, indices[i++], args), ...);
Definition adjacent_find.hpp:9
auto format_to(OutputIt out, etl::string_view fmt, Args const &... args) -> OutputIt
Format args according to the format string fmt, and write the result to the output iterator out.
Definition format_to.hpp:21
constexpr auto ignore_unused(Types &&...) -> void
Explicitly ignore arguments or variables.
Definition ignore_unused.hpp:18
auto format_to_n(OutputIter out, diff_t< OutputIter > n, etl::string_view fmt, Args const &... args) -> format_to_n_result< OutputIter >
Format args according to the format string fmt, and write the result to the output iterator out....
Definition format_to.hpp:70
constexpr auto out() noexcept -> iterator
Returns the iterator to the output buffer.
Definition basic_format_context.hpp:35
constexpr auto operator=(basic_string_view const &view) noexcept -> basic_string_view &=default
Replaces the view with that of view.
constexpr auto empty() const noexcept -> bool
Checks if the view has no characters, i.e. whether size() == 0.
Definition basic_string_view.hpp:215
constexpr auto operator[](size_type pos) const -> const_reference
Returns a const reference to the character at specified location pos.
Definition basic_string_view.hpp:165
constexpr auto size() const noexcept -> size_type
Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()).
Definition basic_string_view.hpp:196
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:48
Dynamically-resizable fixed-capacity vector.
Definition static_vector.hpp:401