mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-05 00:40:12 +00:00
Make undocumented output_range internal
This commit is contained in:
parent
f13906f408
commit
0e72c98043
@ -696,7 +696,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
|||||||
// is not specified.
|
// is not specified.
|
||||||
basic_memory_buffer<Char> buf;
|
basic_memory_buffer<Char> buf;
|
||||||
auto out = std::back_inserter(buf);
|
auto out = std::back_inserter(buf);
|
||||||
typedef output_range<decltype(ctx.out()), Char> range;
|
using range = internal::output_range<decltype(ctx.out()), Char>;
|
||||||
basic_writer<range> w(range(ctx.out()));
|
basic_writer<range> w(range(ctx.out()));
|
||||||
internal::handle_dynamic_spec<internal::width_checker>(
|
internal::handle_dynamic_spec<internal::width_checker>(
|
||||||
spec.width_, width_ref, ctx, format_str.begin());
|
spec.width_, width_ref, ctx, format_str.begin());
|
||||||
|
@ -225,54 +225,35 @@ template <typename T> inline bool use_grisu() {
|
|||||||
sizeof(T) <= sizeof(double);
|
sizeof(T) <= sizeof(double);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A range whose output iterator appends to a buffer.
|
// A range with an iterator appending to a buffer.
|
||||||
template <typename T> class buffer_range {
|
template <typename T> class buffer_range {
|
||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
using iterator = std::back_insert_iterator<internal::buffer<T>>;
|
using iterator = std::back_insert_iterator<buffer<T>>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
iterator begin_;
|
iterator begin_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
buffer_range(internal::buffer<T>& buf) : begin_(std::back_inserter(buf)) {}
|
buffer_range(buffer<T>& buf) : begin_(std::back_inserter(buf)) {}
|
||||||
explicit buffer_range(iterator it) : begin_(it) {}
|
explicit buffer_range(iterator it) : begin_(it) {}
|
||||||
iterator begin() const { return begin_; }
|
iterator begin() const { return begin_; }
|
||||||
};
|
};
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
|
// A range with the specified output iterator and value type.
|
||||||
template <typename OutputIt, typename T = typename OutputIt::value_type>
|
template <typename OutputIt, typename T = typename OutputIt::value_type>
|
||||||
class output_range {
|
class output_range {
|
||||||
private:
|
private:
|
||||||
OutputIt it_;
|
OutputIt it_;
|
||||||
|
|
||||||
// Unused yet.
|
|
||||||
typedef void sentinel;
|
|
||||||
sentinel end() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef OutputIt iterator;
|
using value_type = T;
|
||||||
typedef T value_type;
|
using iterator = OutputIt;
|
||||||
|
|
||||||
explicit output_range(OutputIt it) : it_(it) {}
|
explicit output_range(OutputIt it) : it_(it) {}
|
||||||
OutputIt begin() const { return it_; }
|
OutputIt begin() const { return it_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Range> class basic_writer;
|
|
||||||
using writer = basic_writer<internal::buffer_range<char>>;
|
|
||||||
using wwriter = basic_writer<internal::buffer_range<wchar_t>>;
|
|
||||||
|
|
||||||
/** A formatting error such as invalid format string. */
|
|
||||||
class format_error : public std::runtime_error {
|
|
||||||
public:
|
|
||||||
explicit format_error(const char* message) : std::runtime_error(message) {}
|
|
||||||
explicit format_error(const std::string& message)
|
|
||||||
: std::runtime_error(message) {}
|
|
||||||
~format_error() FMT_NOEXCEPT;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
#ifdef _SECURE_SCL
|
#ifdef _SECURE_SCL
|
||||||
// Make a checked iterator to avoid MSVC warnings.
|
// Make a checked iterator to avoid MSVC warnings.
|
||||||
template <typename T> using checked_ptr = stdext::checked_array_iterator<T*>;
|
template <typename T> using checked_ptr = stdext::checked_array_iterator<T*>;
|
||||||
@ -287,10 +268,9 @@ template <typename T> inline T* make_checked(T* p, std::size_t) { return p; }
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
template <typename U>
|
template <typename U>
|
||||||
void buffer<T>::append(const U* begin, const U* end) {
|
void buffer<T>::append(const U* begin, const U* end) {
|
||||||
std::size_t new_size = size_ + internal::to_unsigned(end - begin);
|
std::size_t new_size = size_ + to_unsigned(end - begin);
|
||||||
reserve(new_size);
|
reserve(new_size);
|
||||||
std::uninitialized_copy(begin, end,
|
std::uninitialized_copy(begin, end, make_checked(ptr_, capacity_) + size_);
|
||||||
internal::make_checked(ptr_, capacity_) + size_);
|
|
||||||
size_ = new_size;
|
size_ = new_size;
|
||||||
}
|
}
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
@ -436,6 +416,19 @@ void basic_memory_buffer<T, SIZE, Allocator>::grow(std::size_t size) {
|
|||||||
typedef basic_memory_buffer<char> memory_buffer;
|
typedef basic_memory_buffer<char> memory_buffer;
|
||||||
typedef basic_memory_buffer<wchar_t> wmemory_buffer;
|
typedef basic_memory_buffer<wchar_t> wmemory_buffer;
|
||||||
|
|
||||||
|
/** A formatting error such as invalid format string. */
|
||||||
|
class format_error : public std::runtime_error {
|
||||||
|
public:
|
||||||
|
explicit format_error(const char* message) : std::runtime_error(message) {}
|
||||||
|
explicit format_error(const std::string& message)
|
||||||
|
: std::runtime_error(message) {}
|
||||||
|
~format_error() FMT_NOEXCEPT;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Range> class basic_writer;
|
||||||
|
using writer = basic_writer<internal::buffer_range<char>>;
|
||||||
|
using wwriter = basic_writer<internal::buffer_range<wchar_t>>;
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// A workaround for std::string not having mutable data() until C++17.
|
// A workaround for std::string not having mutable data() until C++17.
|
||||||
@ -2981,8 +2974,9 @@ struct formatter<T, Char,
|
|||||||
specs_.width_, specs_.width_ref, ctx, format_str_);
|
specs_.width_, specs_.width_ref, ctx, format_str_);
|
||||||
internal::handle_dynamic_spec<internal::precision_checker>(
|
internal::handle_dynamic_spec<internal::precision_checker>(
|
||||||
specs_.precision, specs_.precision_ref, ctx, format_str_);
|
specs_.precision, specs_.precision_ref, ctx, format_str_);
|
||||||
using range_type = output_range<typename FormatContext::iterator,
|
using range_type =
|
||||||
typename FormatContext::char_type>;
|
internal::output_range<typename FormatContext::iterator,
|
||||||
|
typename FormatContext::char_type>;
|
||||||
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
|
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
|
||||||
internal::make_arg<FormatContext>(val));
|
internal::make_arg<FormatContext>(val));
|
||||||
}
|
}
|
||||||
@ -3073,8 +3067,8 @@ template <typename Char = char> class dynamic_formatter {
|
|||||||
else if (specs_.has(HASH_FLAG))
|
else if (specs_.has(HASH_FLAG))
|
||||||
checker.on_hash();
|
checker.on_hash();
|
||||||
if (specs_.precision != -1) checker.end_precision();
|
if (specs_.precision != -1) checker.end_precision();
|
||||||
typedef output_range<typename FormatContext::iterator,
|
typedef internal::output_range<typename FormatContext::iterator,
|
||||||
typename FormatContext::char_type>
|
typename FormatContext::char_type>
|
||||||
range;
|
range;
|
||||||
visit_format_arg(arg_formatter<range>(ctx, nullptr, &specs_),
|
visit_format_arg(arg_formatter<range>(ctx, nullptr, &specs_),
|
||||||
internal::make_arg<FormatContext>(val));
|
internal::make_arg<FormatContext>(val));
|
||||||
@ -3373,7 +3367,7 @@ template <typename S, typename OutputIt, typename... Args,
|
|||||||
inline OutputIt vformat_to(
|
inline OutputIt vformat_to(
|
||||||
OutputIt out, const S& format_str,
|
OutputIt out, const S& format_str,
|
||||||
typename format_args_t<OutputIt, char_t<S>>::type args) {
|
typename format_args_t<OutputIt, char_t<S>>::type args) {
|
||||||
typedef output_range<OutputIt, char_t<S>> range;
|
typedef internal::output_range<OutputIt, char_t<S>> range;
|
||||||
return vformat_to<arg_formatter<range>>(range(out),
|
return vformat_to<arg_formatter<range>>(range(out),
|
||||||
to_string_view(format_str), args);
|
to_string_view(format_str), args);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ template <typename S, typename OutputIt, typename... Args,
|
|||||||
inline OutputIt vformat_to(OutputIt out, const std::locale& loc,
|
inline OutputIt vformat_to(OutputIt out, const std::locale& loc,
|
||||||
const S& format_str,
|
const S& format_str,
|
||||||
typename format_args_t<OutputIt, Char>::type args) {
|
typename format_args_t<OutputIt, Char>::type args) {
|
||||||
using range = output_range<OutputIt, Char>;
|
using range = internal::output_range<OutputIt, Char>;
|
||||||
return vformat_to<arg_formatter<range>>(
|
return vformat_to<arg_formatter<range>>(
|
||||||
range(out), to_string_view(format_str), args, internal::locale_ref(loc));
|
range(out), to_string_view(format_str), args, internal::locale_ref(loc));
|
||||||
}
|
}
|
||||||
|
@ -693,9 +693,8 @@ struct formatter {
|
|||||||
specs_.width_, specs_.width_ref, ctx, nullptr);
|
specs_.width_, specs_.width_ref, ctx, nullptr);
|
||||||
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(
|
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(
|
||||||
specs_.precision, specs_.precision_ref, ctx, nullptr);
|
specs_.precision, specs_.precision_ref, ctx, nullptr);
|
||||||
typedef fmt::output_range<typename FormatContext::iterator,
|
using range_type = fmt::internal::output_range<typename FormatContext::iterator,
|
||||||
typename FormatContext::char_type>
|
typename FormatContext::char_type>;
|
||||||
range_type;
|
|
||||||
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
|
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
|
||||||
basic_format_arg<FormatContext>(val));
|
basic_format_arg<FormatContext>(val));
|
||||||
}
|
}
|
||||||
@ -742,7 +741,7 @@ template<class Out, class... Args>
|
|||||||
|
|
||||||
template<class Out>
|
template<class Out>
|
||||||
Out vformat_to(Out out, string_view fmt, format_args_t<Out, char> args) {
|
Out vformat_to(Out out, string_view fmt, format_args_t<Out, char> args) {
|
||||||
typedef fmt::output_range<Out, char> range;
|
using range = fmt::internal::output_range<Out, char>;
|
||||||
detail::format_handler<detail::arg_formatter<range>, char, basic_format_context<Out, char>>
|
detail::format_handler<detail::arg_formatter<range>, char, basic_format_context<Out, char>>
|
||||||
h(range(out), fmt, args, {});
|
h(range(out), fmt, args, {});
|
||||||
fmt::internal::parse_format_string<false>(fmt::to_string_view(fmt), h);
|
fmt::internal::parse_format_string<false>(fmt::to_string_view(fmt), h);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user