mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-27 15:35:18 +00:00
Purge basic_writer
This commit is contained in:
parent
f0ce21164c
commit
2f05054dd3
@ -383,7 +383,7 @@ OutputIt format_default(OutputIt out, T value) {
|
|||||||
|
|
||||||
template <typename Char, typename OutputIt>
|
template <typename Char, typename OutputIt>
|
||||||
OutputIt format_default(OutputIt out, double value) {
|
OutputIt format_default(OutputIt out, double value) {
|
||||||
writer w(out);
|
basic_writer<buffer_range<char>> w(out);
|
||||||
w.write(value);
|
w.write(value);
|
||||||
return w.out();
|
return w.out();
|
||||||
}
|
}
|
||||||
|
@ -152,13 +152,10 @@ FMT_FUNC void format_error_code(internal::buffer<char>& out, int error_code,
|
|||||||
++error_code_size;
|
++error_code_size;
|
||||||
}
|
}
|
||||||
error_code_size += internal::to_unsigned(internal::count_digits(abs_value));
|
error_code_size += internal::to_unsigned(internal::count_digits(abs_value));
|
||||||
internal::writer w(out);
|
auto it = std::back_inserter(out);
|
||||||
if (message.size() <= inline_buffer_size - error_code_size) {
|
if (message.size() <= inline_buffer_size - error_code_size)
|
||||||
w.write(message);
|
format_to(it, "{}{}", message, SEP);
|
||||||
w.write(SEP);
|
format_to(it, "{}{}", ERROR_STR, error_code);
|
||||||
}
|
|
||||||
w.write(ERROR_STR);
|
|
||||||
w.write(error_code);
|
|
||||||
assert(out.size() <= inline_buffer_size);
|
assert(out.size() <= inline_buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1348,10 +1345,7 @@ FMT_FUNC void format_system_error(internal::buffer<char>& out, int error_code,
|
|||||||
int result =
|
int result =
|
||||||
internal::safe_strerror(error_code, system_message, buf.size());
|
internal::safe_strerror(error_code, system_message, buf.size());
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
internal::writer w(out);
|
format_to(std::back_inserter(out), "{}: {}", message, system_message);
|
||||||
w.write(message);
|
|
||||||
w.write(": ");
|
|
||||||
w.write(system_message);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result != ERANGE)
|
if (result != ERANGE)
|
||||||
|
@ -1751,8 +1751,6 @@ template <typename Range> class basic_writer {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using writer = basic_writer<buffer_range<char>>;
|
|
||||||
|
|
||||||
template <typename T> struct is_integral : std::is_integral<T> {};
|
template <typename T> struct is_integral : std::is_integral<T> {};
|
||||||
template <> struct is_integral<int128_t> : std::true_type {};
|
template <> struct is_integral<int128_t> : std::true_type {};
|
||||||
template <> struct is_integral<uint128_t> : std::true_type {};
|
template <> struct is_integral<uint128_t> : std::true_type {};
|
||||||
|
@ -124,10 +124,7 @@ void internal::format_windows_error(internal::buffer<char>& out, int error_code,
|
|||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
utf16_to_utf8 utf8_message;
|
utf16_to_utf8 utf8_message;
|
||||||
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
|
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
|
||||||
internal::writer w(out);
|
format_to(std::back_inserter(out), "{}: {}", message, utf8_message);
|
||||||
w.write(message);
|
|
||||||
w.write(": ");
|
|
||||||
w.write(utf8_message);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -479,13 +479,6 @@ TEST(StringViewTest, Ctor) {
|
|||||||
EXPECT_EQ(4u, string_view(std::string("defg")).size());
|
EXPECT_EQ(4u, string_view(std::string("defg")).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(WriterTest, Data) {
|
|
||||||
memory_buffer buf;
|
|
||||||
fmt::internal::writer w(buf);
|
|
||||||
w.write(42);
|
|
||||||
EXPECT_EQ("42", to_string(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(WriterTest, WriteInt) {
|
TEST(WriterTest, WriteInt) {
|
||||||
CHECK_WRITE(42);
|
CHECK_WRITE(42);
|
||||||
CHECK_WRITE(-42);
|
CHECK_WRITE(-42);
|
||||||
@ -548,16 +541,14 @@ TEST(WriterTest, WriteLongDouble) {
|
|||||||
|
|
||||||
TEST(WriterTest, WriteDoubleAtBufferBoundary) {
|
TEST(WriterTest, WriteDoubleAtBufferBoundary) {
|
||||||
memory_buffer buf;
|
memory_buffer buf;
|
||||||
fmt::internal::writer writer(buf);
|
for (int i = 0; i < 100; ++i) fmt::format_to(buf, "{}", 1.23456789);
|
||||||
for (int i = 0; i < 100; ++i) writer.write(1.23456789);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(WriterTest, WriteDoubleWithFilledBuffer) {
|
TEST(WriterTest, WriteDoubleWithFilledBuffer) {
|
||||||
memory_buffer buf;
|
memory_buffer buf;
|
||||||
fmt::internal::writer writer(buf);
|
|
||||||
// Fill the buffer.
|
// Fill the buffer.
|
||||||
for (int i = 0; i < fmt::inline_buffer_size; ++i) writer.write(' ');
|
for (int i = 0; i < fmt::inline_buffer_size; ++i) fmt::format_to(buf, " ");
|
||||||
writer.write(1.2);
|
fmt::format_to(buf, "{}", 1.2);
|
||||||
fmt::string_view sv(buf.data(), buf.size());
|
fmt::string_view sv(buf.data(), buf.size());
|
||||||
sv.remove_prefix(fmt::inline_buffer_size);
|
sv.remove_prefix(fmt::inline_buffer_size);
|
||||||
EXPECT_EQ("1.2", sv);
|
EXPECT_EQ("1.2", sv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user