Renamed a bunch of identifiers to make sure there are no clashes with software this might be used in (fmt -> const_fmt)

This commit is contained in:
Andreas Tsouchlos 2022-02-13 17:56:09 +01:00
parent 3db91aebda
commit bb5f4d5272
5 changed files with 19 additions and 19 deletions

View File

@ -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.

View File

@ -22,7 +22,7 @@ namespace const_fmt { namespace const_fmt_detail {
template <ConstString s>
constexpr inline int get_output_len() {
constexpr auto parse_result = parse_string<s>();
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<parse_result.value>();
}
@ -113,7 +113,7 @@ namespace const_fmt {
template <const_fmt_detail::ConstString s, typename... args_t>
constexpr inline auto format(args_t... args) {
constexpr inline auto const_format(args_t... args) {
constexpr auto ast = const_fmt_detail::parse_string<s>().value;
constexpr auto fmt_data = const_fmt_detail::get_fmt_data<ast>();
@ -126,17 +126,17 @@ constexpr inline auto format(args_t... args) {
template <const_fmt_detail::ConstString t_s>
class fmt_literal_obj_t {
class const_fmt_literal_obj_t {
public:
template <typename... args_t>
constexpr auto operator()(args_t... args) {
return format<t_s>(args...);
return const_format<t_s>(args...);
}
};
template <const_fmt_detail::ConstString t_s>
constexpr auto operator""_fmt() {
return fmt_literal_obj_t<t_s>{};
constexpr auto operator""_const_fmt() {
return const_fmt_literal_obj_t<t_s>{};
}

View File

@ -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 {

View File

@ -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<char, N>') into something
// writable to std::cout

View File

@ -9,18 +9,18 @@ using namespace const_fmt::const_fmt_detail;
TEST(Format, positive_int) {
constexpr std::array<char, 8> control1 = {'0', '0', '0', '0',
'0', '0', '0', '2'};
constexpr std::array<char, 8> formatted1 = format<"{:08}">(2);
constexpr std::array<char, 8> formatted1 = const_format<"{:08}">(2);
constexpr std::array<char, 8> control2 = {' ', ' ', ' ', '2',
'2', '2', '2', '2'};
constexpr std::array<char, 8> formatted2 = format<"{:8}">(22222);
constexpr std::array<char, 8> formatted2 = const_format<"{:8}">(22222);
constexpr std::array<char, 8> control3 = {'0', '0', '0', '1',
'2', '3', '4', '5'};
constexpr std::array<char, 8> formatted3 = format<"{:08.4}">(12345);
constexpr std::array<char, 8> formatted3 = const_format<"{:08.4}">(12345);
constexpr std::array<char, 4> control4 = {'6', '7', '8', '9'};
constexpr std::array<char, 4> formatted4 = format<"{:4}">(6789);
constexpr std::array<char, 4> 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<char, 8> control1 = {'-', '0', '0', '0',
'0', '0', '0', '2'};
constexpr std::array<char, 8> formatted1 = format<"{:08}">(-2);
constexpr std::array<char, 8> formatted1 = const_format<"{:08}">(-2);
constexpr std::array<char, 8> control2 = {' ', ' ', '-', '2',
'2', '2', '2', '2'};
constexpr std::array<char, 8> formatted2 = format<"{:8}">(-22222);
constexpr std::array<char, 8> formatted2 = const_format<"{:8}">(-22222);
constexpr std::array<char, 8> control3 = {'-', '0', '0', '1',
'2', '3', '4', '5'};
constexpr std::array<char, 8> formatted3 = format<"{:08.4}">(-12345);
constexpr std::array<char, 8> formatted3 = const_format<"{:08.4}">(-12345);
constexpr std::array<char, 5> control4 = {'-', '6', '7', '8', '9'};
constexpr std::array<char, 5> formatted4 = format<"{:5}">(-6789);
constexpr std::array<char, 5> formatted4 = const_format<"{:5}">(-6789);
EXPECT_EQ(control1, formatted1);
EXPECT_EQ(control2, formatted2);