mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-05 00:40:12 +00:00
Add missing presentation type checks for std::string (#2402)
This commit is contained in:
parent
889bbf27a2
commit
1d7384530e
@ -2577,8 +2577,8 @@ FMT_CONSTEXPR auto check_cstring_type_spec(Char spec, ErrorHandler&& eh = {})
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename ErrorHandler>
|
template <typename Char, typename ErrorHandler = error_handler>
|
||||||
FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler&& eh) {
|
FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler&& eh = {}) {
|
||||||
if (spec != 0 && spec != 's') eh.on_error("invalid type specifier");
|
if (spec != 0 && spec != 's') eh.on_error("invalid type specifier");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1569,6 +1569,7 @@ FMT_CONSTEXPR auto write(OutputIt out,
|
|||||||
basic_string_view<type_identity_t<Char>> s,
|
basic_string_view<type_identity_t<Char>> s,
|
||||||
const basic_format_specs<Char>& specs, locale_ref)
|
const basic_format_specs<Char>& specs, locale_ref)
|
||||||
-> OutputIt {
|
-> OutputIt {
|
||||||
|
check_string_type_spec(specs.type);
|
||||||
return write(out, s, specs);
|
return write(out, s, specs);
|
||||||
}
|
}
|
||||||
template <typename Char, typename OutputIt>
|
template <typename Char, typename OutputIt>
|
||||||
|
@ -1390,6 +1390,8 @@ TEST(format_test, format_pointer) {
|
|||||||
|
|
||||||
TEST(format_test, format_string) {
|
TEST(format_test, format_string) {
|
||||||
EXPECT_EQ("test", fmt::format("{0}", std::string("test")));
|
EXPECT_EQ("test", fmt::format("{0}", std::string("test")));
|
||||||
|
EXPECT_THROW(fmt::format(fmt::runtime("{:x}"), std::string("test")),
|
||||||
|
fmt::format_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(format_test, format_string_view) {
|
TEST(format_test, format_string_view) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user