forked from fmtlib/fmt
Remove undocumented buffer_range and output_range
This commit is contained in:
@ -495,22 +495,6 @@ class truncating_iterator<OutputIt, std::true_type>
|
|||||||
truncating_iterator& operator*() { return *this; }
|
truncating_iterator& operator*() { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// A range with the specified output iterator and value type.
|
|
||||||
template <typename OutputIt, typename T = typename OutputIt::value_type>
|
|
||||||
class output_range {
|
|
||||||
private:
|
|
||||||
OutputIt it_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
using value_type = T;
|
|
||||||
using iterator = OutputIt;
|
|
||||||
struct sentinel {};
|
|
||||||
|
|
||||||
explicit output_range(OutputIt it) : it_(it) {}
|
|
||||||
OutputIt begin() const { return it_; }
|
|
||||||
sentinel end() const { return {}; } // Sentinel is not used yet.
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
inline size_t count_code_points(basic_string_view<Char> s) {
|
inline size_t count_code_points(basic_string_view<Char> s) {
|
||||||
return s.size();
|
return s.size();
|
||||||
@ -587,18 +571,6 @@ void buffer<T>::append(const U* begin, const U* end) {
|
|||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
// DEPRECATED! A range with an iterator appending to a buffer.
|
|
||||||
template <typename T>
|
|
||||||
class buffer_range
|
|
||||||
: public detail::output_range<std::back_insert_iterator<detail::buffer<T>>,
|
|
||||||
T> {
|
|
||||||
public:
|
|
||||||
using iterator = std::back_insert_iterator<detail::buffer<T>>;
|
|
||||||
using detail::output_range<iterator, T>::output_range;
|
|
||||||
buffer_range(detail::buffer<T>& buf)
|
|
||||||
: detail::output_range<iterator, T>(std::back_inserter(buf)) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
// The number of characters to store in the basic_memory_buffer object itself
|
// The number of characters to store in the basic_memory_buffer object itself
|
||||||
// to avoid dynamic memory allocation.
|
// to avoid dynamic memory allocation.
|
||||||
enum { inline_buffer_size = 500 };
|
enum { inline_buffer_size = 500 };
|
||||||
|
@ -194,8 +194,6 @@ FMT_DEPRECATED void printf(detail::buffer<Char>& buf,
|
|||||||
}
|
}
|
||||||
using detail::vprintf;
|
using detail::vprintf;
|
||||||
|
|
||||||
template <typename Range> class printf_arg_formatter;
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class basic_printf_parse_context : public basic_format_parse_context<Char> {
|
class basic_printf_parse_context : public basic_format_parse_context<Char> {
|
||||||
using basic_format_parse_context<Char>::basic_format_parse_context;
|
using basic_format_parse_context<Char>::basic_format_parse_context;
|
||||||
@ -207,18 +205,16 @@ template <typename OutputIt, typename Char> class basic_printf_context;
|
|||||||
The ``printf`` argument formatter.
|
The ``printf`` argument formatter.
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename Range>
|
template <typename OutputIt, typename Char>
|
||||||
class printf_arg_formatter
|
class printf_arg_formatter
|
||||||
: public detail::arg_formatter_base<typename Range::iterator,
|
: public detail::arg_formatter_base<OutputIt, Char> {
|
||||||
typename Range::value_type> {
|
|
||||||
public:
|
public:
|
||||||
using iterator = typename Range::iterator;
|
using iterator = OutputIt;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using char_type = typename Range::value_type;
|
using char_type = Char;
|
||||||
using base = detail::arg_formatter_base<typename Range::iterator,
|
using base = detail::arg_formatter_base<OutputIt, Char>;
|
||||||
typename Range::value_type>;
|
using context_type = basic_printf_context<OutputIt, Char>;
|
||||||
using context_type = basic_printf_context<iterator, char_type>;
|
|
||||||
|
|
||||||
context_type& context_;
|
context_type& context_;
|
||||||
|
|
||||||
@ -389,7 +385,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Formats stored arguments and writes the output to the range. */
|
/** Formats stored arguments and writes the output to the range. */
|
||||||
template <typename ArgFormatter = printf_arg_formatter<buffer_range<Char>>>
|
template <typename ArgFormatter = printf_arg_formatter<OutputIt, Char>>
|
||||||
OutputIt format();
|
OutputIt format();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,10 +65,10 @@ TEST(OStreamTest, Enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct test_arg_formatter
|
struct test_arg_formatter
|
||||||
: fmt::arg_formatter<fmt::buffer_range<char>::iterator, char> {
|
: fmt::arg_formatter<fmt::format_context::iterator, char> {
|
||||||
fmt::format_parse_context parse_ctx;
|
fmt::format_parse_context parse_ctx;
|
||||||
test_arg_formatter(fmt::format_context& ctx, fmt::format_specs& s)
|
test_arg_formatter(fmt::format_context& ctx, fmt::format_specs& s)
|
||||||
: fmt::arg_formatter<fmt::buffer_range<char>::iterator, char>(
|
: fmt::arg_formatter<fmt::format_context::iterator, char>(
|
||||||
ctx, &parse_ctx, &s),
|
ctx, &parse_ctx, &s),
|
||||||
parse_ctx("") {}
|
parse_ctx("") {}
|
||||||
};
|
};
|
||||||
|
@ -606,52 +606,3 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) {
|
|||||||
{fmt::make_wprintf_args(42, L"something")}));
|
{fmt::make_wprintf_args(42, L"something")}));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef fmt::printf_arg_formatter<fmt::buffer_range<char>> formatter_t;
|
|
||||||
typedef fmt::basic_printf_context<formatter_t::iterator, char> context_t;
|
|
||||||
|
|
||||||
// A custom printf argument formatter that doesn't print `-` for floating-point
|
|
||||||
// values rounded to 0.
|
|
||||||
class custom_printf_arg_formatter : public formatter_t {
|
|
||||||
public:
|
|
||||||
using formatter_t::iterator;
|
|
||||||
|
|
||||||
custom_printf_arg_formatter(formatter_t::iterator iter,
|
|
||||||
formatter_t::format_specs& specs, context_t& ctx)
|
|
||||||
: formatter_t(iter, specs, ctx) {}
|
|
||||||
|
|
||||||
using formatter_t::operator();
|
|
||||||
|
|
||||||
#if FMT_MSC_VER > 0 && FMT_MSC_VER <= 1804
|
|
||||||
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
|
||||||
iterator operator()(T value){
|
|
||||||
#else
|
|
||||||
iterator operator()(double value) {
|
|
||||||
#endif
|
|
||||||
// Comparing a float to 0.0 is safe.
|
|
||||||
if (round(value * pow(10, specs()->precision)) == 0.0) value = 0;
|
|
||||||
return formatter_t::operator()(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
typedef fmt::basic_format_args<context_t> format_args_t;
|
|
||||||
|
|
||||||
std::string custom_vformat(fmt::string_view format_str, format_args_t args) {
|
|
||||||
fmt::memory_buffer buffer;
|
|
||||||
fmt::vprintf<custom_printf_arg_formatter>(buffer, format_str, args);
|
|
||||||
return std::string(buffer.data(), buffer.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
std::string custom_format(const char* format_str, const Args&... args) {
|
|
||||||
auto va = fmt::make_printf_args(args...);
|
|
||||||
return custom_vformat(format_str, {va});
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(PrintfTest, CustomFormat) {
|
|
||||||
EXPECT_EQ("0.00", custom_format("%.2f", -.00001));
|
|
||||||
EXPECT_EQ("0.00", custom_format("%.2f", .00001));
|
|
||||||
EXPECT_EQ("1.00", custom_format("%.2f", 1.00001));
|
|
||||||
EXPECT_EQ("-1.00", custom_format("%.2f", -1.00001));
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user