diff --git a/inc/format.h b/inc/format.h index 3977b02..907d1d8 100644 --- a/inc/format.h +++ b/inc/format.h @@ -31,7 +31,7 @@ constexpr bool is_valid_type() { return true; } -template +template constexpr std::array format_arg(T arg) { static_assert(is_valid_type(), "Invalid argument type"); @@ -44,6 +44,25 @@ constexpr std::array format_arg(T arg) { } +template +constexpr char_array_t format_args(char_array_t result, first_arg_t first_arg, other_args_t... other_args) { + if constexpr(t_ast_i >= t_ast.size()) { + return result; + } else { + if (t_ast[t_ast_i].is_char()) { + result[t_result_i] = t_ast[t_ast_i].get_char(); + return format_args(result, first_arg, other_args...); + } else { + const auto formatted_arg = format_arg(first_arg); + + std::copy(formatted_arg.begin(), formatted_arg.end(), result.begin()+t_result_i); + + return format_args(result, first_arg, other_args...); + } + } +} + + } // namespace detail @@ -54,7 +73,7 @@ std::array()> format(args_t... args) { std::array()> result; - return result; + return detail::format_args(result, args...); } diff --git a/inc/parse_types.h b/inc/parse_types.h index 31930b9..c4e69dd 100644 --- a/inc/parse_types.h +++ b/inc/parse_types.h @@ -46,10 +46,8 @@ public: return m_is_char; } -private: - bool m_is_char = false; - - char m_c = 'c'; + bool m_is_char = false; + char m_c = 'c'; fmt_node_t m_node; }; @@ -58,4 +56,4 @@ template using string_result_t = std::array; -#endif //LOGGER_PARSE_TYPES_H +#endif // LOGGER_PARSE_TYPES_H diff --git a/src/main.cpp b/src/main.cpp index 7a526b6..7c4986b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,9 +12,13 @@ public: int main() { - constexpr detail::ConstString s{"Test: {:16.8f} {:03.5} {:08.2}"}; + constexpr detail::ConstString s{"Test: {:3.8f} {:02.5} {:05.2}"}; const auto formatted = format(3.4, "abc", 8.98754); + for (const auto& c : formatted) + std::cout << c; + std::cout << std::endl; + return 0; } \ No newline at end of file