From afa7831e93c12d1da35d120cc3e31e4764f5f59f Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Thu, 25 Nov 2021 16:25:39 +0100 Subject: [PATCH] Fixed parse issues: Format Type not being correctly parsed --- inc/format.h | 2 +- inc/parse.h | 36 +++++++++++++++++------------------- src/main.cpp | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/inc/format.h b/inc/format.h index ac3f0a1..e607d5b 100644 --- a/inc/format.h +++ b/inc/format.h @@ -138,7 +138,7 @@ class fmt_literal_obj_t { }; template -constexpr auto operator""_const_fmt() { +constexpr auto operator""_fmt() { return fmt_literal_obj_t{}; } diff --git a/inc/parse.h b/inc/parse.h index ab1a161..6ca6af3 100644 --- a/inc/parse.h +++ b/inc/parse.h @@ -118,44 +118,42 @@ constexpr parse_result_t parse_number(unsigned i) { template constexpr parse_result_t parse_type(unsigned i) { - ++i; switch (s[i]) { case 's': - return {true, i, FormatType::s}; + return {true, ++i, FormatType::s}; case 'c': - return {true, i, FormatType::c}; + return {true, ++i, FormatType::c}; case 'b': - return {true, i, FormatType::b}; + return {true, ++i, FormatType::b}; case 'B': - return {true, i, FormatType::B}; + return {true, ++i, FormatType::B}; case 'd': - return {true, i, FormatType::d}; + return {true, ++i, FormatType::d}; case 'o': - return {true, i, FormatType::o}; + return {true, ++i, FormatType::o}; case 'x': - return {true, i, FormatType::x}; + return {true, ++i, FormatType::x}; case 'X': - return {true, i, FormatType::X}; + return {true, ++i, FormatType::X}; case 'a': - return {true, i, FormatType::a}; + return {true, ++i, FormatType::a}; case 'A': - return {true, i, FormatType::A}; + return {true, ++i, FormatType::A}; case 'e': - return {true, i, FormatType::e}; + return {true, ++i, FormatType::e}; case 'E': - return {true, i, FormatType::E}; + return {true, ++i, FormatType::E}; case 'f': - return {true, i, FormatType::f}; + return {true, ++i, FormatType::f}; case 'F': - return {true, i, FormatType::F}; + return {true, ++i, FormatType::F}; case 'g': - return {true, i, FormatType::g}; + return {true, ++i, FormatType::g}; case 'G': - return {true, i, FormatType::G}; + return {true, ++i, FormatType::G}; case 'p': - return {true, i, FormatType::p}; + return {true, ++i, FormatType::p}; default: - --i; return {false, i, FormatType::s}; } } diff --git a/src/main.cpp b/src/main.cpp index b37273d..84c5cb3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ int main() { - constexpr auto formatted = "Test: {:012.5} {:6} {:8}"_const_fmt(142.4334, "abcdef", -1234); + constexpr auto formatted = "Test: {:012.5} {:6} {:8}"_fmt(142.4334, "abcdef", -1234); for (const auto& c : formatted) std::cout << c;