HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
format_check.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/utility.hpp"
8#include "../macros.hpp"
9#include <string_view>
10#include <type_traits>
11
12
13
14namespace hi::inline v1 {
15
24constexpr int format_count(std::string_view fmt) noexcept
25{
26 auto num_args = 0;
27 auto o_count = 0;
28 auto c_count = 0;
29 auto is_open = false;
30 auto prev = ' ';
31 for (auto c : fmt) {
32 if (c != prev) {
33 if (o_count % 2) {
34 if (is_open) {
35 return -1;
36 }
37 is_open = true;
38
39 } else if (c_count % 2) {
40 if (not is_open) {
41 return -2;
42 }
43 ++num_args;
44 is_open = false;
45 }
46 }
47
48 o_count = c == '{' ? o_count + 1 : 0;
49 c_count = c == '}' ? c_count + 1 : 0;
50 prev = c;
51 }
52
53 if (c_count % 2) {
54 if (not is_open) {
55 return -2;
56 }
57 ++num_args;
58
59 } else if (is_open) {
60 return -3;
61 }
62
63 return num_args;
64}
65
66} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr int format_count(std::string_view fmt) noexcept
Count arguments of a std::format format string.
Definition format_check.hpp:24
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377