mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-26 00:21:13 +00:00
Grow buffer
This commit is contained in:
parent
fa5ebd27d4
commit
49f6771ca9
17
fmt/time.h
17
fmt/time.h
@ -42,14 +42,21 @@ void format(BasicFormatter<char, ArgFormatter> &f,
|
|||||||
++end;
|
++end;
|
||||||
if (*end != '}')
|
if (*end != '}')
|
||||||
FMT_THROW(FormatError("missing '}' in format string"));
|
FMT_THROW(FormatError("missing '}' in format string"));
|
||||||
Buffer<char> &buffer = f.writer().buffer();
|
|
||||||
std::size_t start = buffer.size();
|
|
||||||
internal::MemoryBuffer<char, internal::INLINE_BUFFER_SIZE> format;
|
internal::MemoryBuffer<char, internal::INLINE_BUFFER_SIZE> format;
|
||||||
format.append(format_str, end + 1);
|
format.append(format_str, end + 1);
|
||||||
format[format.size() - 1] = '\0';
|
format[format.size() - 1] = '\0';
|
||||||
std::size_t size = std::strftime(&buffer[start], buffer.capacity() - start,
|
Buffer<char> &buffer = f.writer().buffer();
|
||||||
&format[0], &tm);
|
std::size_t start = buffer.size();
|
||||||
buffer.resize(start + size);
|
for (;;) {
|
||||||
|
std::size_t size = buffer.capacity() - start;
|
||||||
|
std::size_t count = std::strftime(&buffer[start], size, &format[0], &tm);
|
||||||
|
if (count != 0) {
|
||||||
|
buffer.resize(start + count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
enum {MIN_GROWTH = 10};
|
||||||
|
buffer.reserve(buffer.capacity() + size > MIN_GROWTH ? size : MIN_GROWTH);
|
||||||
|
}
|
||||||
format_str = end + 1;
|
format_str = end + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user