mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Remove printf_arg_formatter from format.h and cleanup
This commit is contained in:
26
fmt/format.h
26
fmt/format.h
@ -356,30 +356,22 @@ namespace fmt {
|
|||||||
using std::move;
|
using std::move;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename Char>
|
|
||||||
class basic_buffer;
|
|
||||||
|
|
||||||
typedef basic_buffer<char> buffer;
|
|
||||||
typedef basic_buffer<wchar_t> wbuffer;
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class basic_writer;
|
class basic_writer;
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
class basic_arg;
|
class basic_arg;
|
||||||
|
|
||||||
template <typename Char>
|
|
||||||
class arg_formatter;
|
|
||||||
|
|
||||||
template <typename Char>
|
|
||||||
class printf_arg_formatter;
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class basic_context;
|
class basic_context;
|
||||||
|
|
||||||
typedef basic_context<char> context;
|
typedef basic_context<char> context;
|
||||||
typedef basic_context<wchar_t> wcontext;
|
typedef basic_context<wchar_t> wcontext;
|
||||||
|
|
||||||
|
// A formatter for objects of type T.
|
||||||
|
template <typename T, typename Char = char, typename Enable = void>
|
||||||
|
struct formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
|
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
|
||||||
@ -482,10 +474,6 @@ class format_error : public std::runtime_error {
|
|||||||
~format_error() throw();
|
~format_error() throw();
|
||||||
};
|
};
|
||||||
|
|
||||||
// A formatter for objects of type T.
|
|
||||||
template <typename T, typename Char = char, typename Enable = void>
|
|
||||||
struct formatter;
|
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// Casts nonnegative integer to unsigned.
|
// Casts nonnegative integer to unsigned.
|
||||||
@ -589,6 +577,9 @@ class basic_buffer {
|
|||||||
virtual std::locale locale() const { return std::locale(); }
|
virtual std::locale locale() const { return std::locale(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef basic_buffer<char> buffer;
|
||||||
|
typedef basic_buffer<wchar_t> wbuffer;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void basic_buffer<T>::append(const U *begin, const U *end) {
|
void basic_buffer<T>::append(const U *begin, const U *end) {
|
||||||
@ -2304,9 +2295,6 @@ class basic_writer {
|
|||||||
template <typename Char_>
|
template <typename Char_>
|
||||||
friend class internal::arg_formatter_base;
|
friend class internal::arg_formatter_base;
|
||||||
|
|
||||||
template <typename Char_>
|
|
||||||
friend class printf_arg_formatter;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
Constructs a ``basic_writer`` object.
|
Constructs a ``basic_writer`` object.
|
||||||
|
22
fmt/printf.h
22
fmt/printf.h
@ -241,25 +241,13 @@ class printf_arg_formatter : public internal::arg_formatter_base<Char> {
|
|||||||
|
|
||||||
/** Formats a character. */
|
/** Formats a character. */
|
||||||
void operator()(Char value) {
|
void operator()(Char value) {
|
||||||
const format_specs &fmt_spec = this->spec();
|
format_specs &fmt_spec = this->spec();
|
||||||
basic_writer<Char> &w = this->writer();
|
basic_writer<Char> &w = this->writer();
|
||||||
if (fmt_spec.type_ && fmt_spec.type_ != 'c')
|
if (fmt_spec.type_ && fmt_spec.type_ != 'c')
|
||||||
w.write_int(value, fmt_spec);
|
return (*this)(static_cast<int>(value));
|
||||||
typedef typename basic_writer<Char>::pointer_type pointer_type;
|
fmt_spec.flags_ = 0;
|
||||||
pointer_type out = pointer_type();
|
fmt_spec.align_ = ALIGN_RIGHT;
|
||||||
if (fmt_spec.width_ > 1) {
|
Base::operator()(value);
|
||||||
Char fill = ' ';
|
|
||||||
out = w.grow_buffer(fmt_spec.width_);
|
|
||||||
if (fmt_spec.align_ != ALIGN_LEFT) {
|
|
||||||
std::fill_n(out, fmt_spec.width_ - 1, fill);
|
|
||||||
out += fmt_spec.width_ - 1;
|
|
||||||
} else {
|
|
||||||
std::fill_n(out + 1, fmt_spec.width_ - 1, fill);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out = w.grow_buffer(1);
|
|
||||||
}
|
|
||||||
*out = static_cast<Char>(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Formats a null-terminated C string. */
|
/** Formats a null-terminated C string. */
|
||||||
|
@ -137,7 +137,7 @@ TEST(PrintfTest, ZeroFlag) {
|
|||||||
EXPECT_PRINTF("+00042", "%00+6d", 42);
|
EXPECT_PRINTF("+00042", "%00+6d", 42);
|
||||||
|
|
||||||
// '0' flag is ignored for non-numeric types.
|
// '0' flag is ignored for non-numeric types.
|
||||||
EXPECT_PRINTF(" x", "%05c", 'x');
|
EXPECT_PRINTF("0000x", "%05c", 'x');
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(PrintfTest, PlusFlag) {
|
TEST(PrintfTest, PlusFlag) {
|
||||||
|
Reference in New Issue
Block a user