mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Increment output iterator in basic_writer::write for character types (#1056)
This commit is contained in:
parent
a97757736b
commit
287eaab3b2
@ -2755,10 +2755,14 @@ template <typename Range> class basic_writer {
|
||||
void write(long double value) { write_double(value, format_specs()); }
|
||||
|
||||
/** Writes a character to the buffer. */
|
||||
void write(char value) { *reserve(1) = value; }
|
||||
void write(char value) {
|
||||
auto&& it = reserve(1);
|
||||
*it++ = value;
|
||||
}
|
||||
void write(wchar_t value) {
|
||||
static_assert(std::is_same<char_type, wchar_t>::value, "");
|
||||
*reserve(1) = value;
|
||||
auto&& it = reserve(1);
|
||||
*it++ = value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2040,6 +2040,17 @@ TEST(FormatTest, FormatToN) {
|
||||
EXPECT_EQ(6u, result.size);
|
||||
EXPECT_EQ(buffer + 3, result.out);
|
||||
EXPECT_EQ("foox", fmt::string_view(buffer, 4));
|
||||
buffer[0] = 'x';
|
||||
buffer[1] = 'x';
|
||||
buffer[2] = 'x';
|
||||
result = fmt::format_to_n(buffer, 3, "{}", 'A');
|
||||
EXPECT_EQ(1u, result.size);
|
||||
EXPECT_EQ(buffer + 1, result.out);
|
||||
EXPECT_EQ("Axxx", fmt::string_view(buffer, 4));
|
||||
result = fmt::format_to_n(buffer, 3, "{}{} ", 'B', 'C');
|
||||
EXPECT_EQ(3u, result.size);
|
||||
EXPECT_EQ(buffer + 3, result.out);
|
||||
EXPECT_EQ("BC x", fmt::string_view(buffer, 4));
|
||||
}
|
||||
|
||||
TEST(FormatTest, WideFormatToN) {
|
||||
@ -2049,6 +2060,17 @@ TEST(FormatTest, WideFormatToN) {
|
||||
EXPECT_EQ(5u, result.size);
|
||||
EXPECT_EQ(buffer + 3, result.out);
|
||||
EXPECT_EQ(L"123x", fmt::wstring_view(buffer, 4));
|
||||
buffer[0] = L'x';
|
||||
buffer[1] = L'x';
|
||||
buffer[2] = L'x';
|
||||
result = fmt::format_to_n(buffer, 3, L"{}", L'A');
|
||||
EXPECT_EQ(1u, result.size);
|
||||
EXPECT_EQ(buffer + 1, result.out);
|
||||
EXPECT_EQ(L"Axxx", fmt::wstring_view(buffer, 4));
|
||||
result = fmt::format_to_n(buffer, 3, L"{}{} ", L'B', L'C');
|
||||
EXPECT_EQ(3u, result.size);
|
||||
EXPECT_EQ(buffer + 3, result.out);
|
||||
EXPECT_EQ(L"BC x", fmt::wstring_view(buffer, 4));
|
||||
}
|
||||
|
||||
#if FMT_USE_CONSTEXPR
|
||||
|
Loading…
Reference in New Issue
Block a user