mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-27 06:35:37 +00:00
Fix handling of empty string_view (#689)
This commit is contained in:
parent
a24005d5fd
commit
8c29459eda
@ -1399,8 +1399,9 @@ class arg_formatter_base {
|
||||
}
|
||||
|
||||
void write(const char_type *value) {
|
||||
auto length = value != FMT_NULL ?
|
||||
std::char_traits<char_type>::length(value) : 0;
|
||||
if (!value)
|
||||
FMT_THROW(format_error("string pointer is null"));
|
||||
auto length = std::char_traits<char_type>::length(value);
|
||||
writer_.write_str(basic_string_view<char_type>(value, length), specs_);
|
||||
}
|
||||
|
||||
@ -2647,8 +2648,6 @@ void basic_writer<Range>::write_str(
|
||||
internal::char_traits<char_type>::convert(Char());
|
||||
const Char *data = s.data();
|
||||
std::size_t size = s.size();
|
||||
if (size == 0 && !data)
|
||||
FMT_THROW(format_error("string pointer is null"));
|
||||
std::size_t precision = static_cast<std::size_t>(spec.precision_);
|
||||
if (spec.precision_ >= 0 && precision < size)
|
||||
size = precision;
|
||||
|
@ -1196,7 +1196,8 @@ TEST(FormatterTest, FormatString) {
|
||||
}
|
||||
|
||||
TEST(FormatterTest, FormatStringView) {
|
||||
EXPECT_EQ("test", format("{0}", string_view("test")));
|
||||
EXPECT_EQ("test", format("{}", string_view("test")));
|
||||
EXPECT_EQ("", format("{}", string_view()));
|
||||
}
|
||||
|
||||
#ifdef FMT_USE_STD_STRING_VIEW
|
||||
|
Loading…
x
Reference in New Issue
Block a user