diff --git a/README.md b/README.md index 08b385e..f61ea8e 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ $ ctest --test-dir build/ ## Limitations Only a relatively limited subset of the `fmtlib` syntax is recognized (for now anyway). In particular, -there is no support for positional arguments, alignment, chrono format specs and custom format specifications. +there is no support for positional arguments, alignment, chrono format specs and custom const_format specifications. -By nature of the library design, which forces compile-time preprocessing of the format string, no dynamic width or +By nature of the library design, which forces compile-time preprocessing of the const_format string, no dynamic width or dynamic precision can be implemented. diff --git a/const_fmt/format.h b/const_fmt/format.h index 45806e1..c6242ea 100644 --- a/const_fmt/format.h +++ b/const_fmt/format.h @@ -22,7 +22,7 @@ namespace const_fmt { namespace const_fmt_detail { template constexpr inline int get_output_len() { constexpr auto parse_result = parse_string(); - static_assert(parse_result.is_valid, "Syntax error in format string"); + static_assert(parse_result.is_valid, "Syntax error in const_format string"); return get_ast_output_len(); } @@ -113,7 +113,7 @@ namespace const_fmt { template -constexpr inline auto format(args_t... args) { +constexpr inline auto const_format(args_t... args) { constexpr auto ast = const_fmt_detail::parse_string().value; constexpr auto fmt_data = const_fmt_detail::get_fmt_data(); @@ -126,17 +126,17 @@ constexpr inline auto format(args_t... args) { template -class fmt_literal_obj_t { +class const_fmt_literal_obj_t { public: template constexpr auto operator()(args_t... args) { - return format(args...); + return const_format(args...); } }; template -constexpr auto operator""_fmt() { - return fmt_literal_obj_t{}; +constexpr auto operator""_const_fmt() { + return const_fmt_literal_obj_t{}; } diff --git a/const_fmt/parse.h b/const_fmt/parse.h index e5350b6..f8260c5 100644 --- a/const_fmt/parse.h +++ b/const_fmt/parse.h @@ -5,7 +5,7 @@ #include "types.h" -// clang-format off +// clang-const_format off /* * @@ -34,7 +34,7 @@ * */ -// clang-format on +// clang-const_format on namespace const_fmt { namespace const_fmt_detail { diff --git a/examples/src/examples.cpp b/examples/src/examples.cpp index ba73545..b69718d 100644 --- a/examples/src/examples.cpp +++ b/examples/src/examples.cpp @@ -5,7 +5,7 @@ using namespace const_fmt; int main() { - constexpr auto s = "abcdef {:04}"_fmt(123); + constexpr auto s = "abcdef {:04}"_const_fmt(123); // Convert the s (with a type of 'std::array') into something // writable to std::cout diff --git a/test/src/format.cpp b/test/src/format.cpp index 0c1344c..00f53d9 100644 --- a/test/src/format.cpp +++ b/test/src/format.cpp @@ -9,18 +9,18 @@ using namespace const_fmt::const_fmt_detail; TEST(Format, positive_int) { constexpr std::array control1 = {'0', '0', '0', '0', '0', '0', '0', '2'}; - constexpr std::array formatted1 = format<"{:08}">(2); + constexpr std::array formatted1 = const_format<"{:08}">(2); constexpr std::array control2 = {' ', ' ', ' ', '2', '2', '2', '2', '2'}; - constexpr std::array formatted2 = format<"{:8}">(22222); + constexpr std::array formatted2 = const_format<"{:8}">(22222); constexpr std::array control3 = {'0', '0', '0', '1', '2', '3', '4', '5'}; - constexpr std::array formatted3 = format<"{:08.4}">(12345); + constexpr std::array formatted3 = const_format<"{:08.4}">(12345); constexpr std::array control4 = {'6', '7', '8', '9'}; - constexpr std::array formatted4 = format<"{:4}">(6789); + constexpr std::array formatted4 = const_format<"{:4}">(6789); EXPECT_EQ(control1, formatted1); EXPECT_EQ(control2, formatted2); @@ -31,18 +31,18 @@ TEST(Format, positive_int) { TEST(Format, negative_int) { constexpr std::array control1 = {'-', '0', '0', '0', '0', '0', '0', '2'}; - constexpr std::array formatted1 = format<"{:08}">(-2); + constexpr std::array formatted1 = const_format<"{:08}">(-2); constexpr std::array control2 = {' ', ' ', '-', '2', '2', '2', '2', '2'}; - constexpr std::array formatted2 = format<"{:8}">(-22222); + constexpr std::array formatted2 = const_format<"{:8}">(-22222); constexpr std::array control3 = {'-', '0', '0', '1', '2', '3', '4', '5'}; - constexpr std::array formatted3 = format<"{:08.4}">(-12345); + constexpr std::array formatted3 = const_format<"{:08.4}">(-12345); constexpr std::array control4 = {'-', '6', '7', '8', '9'}; - constexpr std::array formatted4 = format<"{:5}">(-6789); + constexpr std::array formatted4 = const_format<"{:5}">(-6789); EXPECT_EQ(control1, formatted1); EXPECT_EQ(control2, formatted2);