tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
basic_format_parse_context.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_FORMAT_BASIC_FORMAT_PARSE_CONTEXT_HPP
5#define TETL_FORMAT_BASIC_FORMAT_PARSE_CONTEXT_HPP
6
7#include <etl/_cstddef/ptrdiff_t.hpp>
8#include <etl/_cstddef/size_t.hpp>
9#include <etl/_string_view/basic_string_view.hpp>
10
11namespace etl {
12
13template <typename CharT>
15 using char_type = CharT;
16 using const_iterator = typename basic_string_view<CharT>::const_iterator;
17 using iterator = const_iterator;
18
19 constexpr explicit basic_format_parse_context(basic_string_view<CharT> fmt, size_t numArgs = 0) noexcept
20 : _begin{fmt.begin()}
21 , _end{fmt.end()}
22 , _numArgs{numArgs}
23 {
24 }
25
28
29 [[nodiscard]] constexpr auto begin() const noexcept -> const_iterator
30 {
31 return _begin;
32 }
33
34 [[nodiscard]] constexpr auto end() const noexcept -> const_iterator
35 {
36 return _end;
37 }
38
39 constexpr auto advance_to(const_iterator it) -> void
40 {
41 _begin = it;
42 }
43
44 [[nodiscard]] constexpr auto next_arg_id() -> size_t
45 {
46 return static_cast<size_t>(_nextArgId++);
47 }
48
49 constexpr auto check_arg_id(size_t /*id*/) -> void
50 {
51 _nextArgId = -1;
52 }
53
54private:
55 // next_arg_id_ > 0 means automatic
56 // next_arg_id_ == 0 means unknown
57 // next_arg_id_ < 0 means manual
58
59 iterator _begin;
60 iterator _end;
61 size_t _numArgs;
62 ptrdiff_t _nextArgId{};
63};
64
65using format_parse_context = basic_format_parse_context<char>;
66using wformat_parse_context = basic_format_parse_context<wchar_t>;
67
68} // namespace etl
69
70#endif // TETL_FORMAT_BASIC_FORMAT_PARSE_CONTEXT_HPP
Definition adjacent_find.hpp:9
Definition basic_format_parse_context.hpp:14
basic_format_parse_context(basic_format_parse_context const &other)=delete
constexpr basic_format_parse_context(basic_string_view< CharT > fmt, size_t numArgs=0) noexcept
Definition basic_format_parse_context.hpp:19
constexpr auto check_arg_id(size_t) -> void
Definition basic_format_parse_context.hpp:49
constexpr auto begin() const noexcept -> const_iterator
Definition basic_format_parse_context.hpp:29
constexpr auto next_arg_id() -> size_t
Definition basic_format_parse_context.hpp:44
auto operator=(basic_format_parse_context const &other) -> basic_format_parse_context &=delete
constexpr auto advance_to(const_iterator it) -> void
Definition basic_format_parse_context.hpp:39
constexpr auto end() const noexcept -> const_iterator
Definition basic_format_parse_context.hpp:34
The class template basic_string_view describes an object that can refer to a constant contiguous sequ...
Definition basic_string_view.hpp:35