mirror of
https://github.com/fmtlib/fmt.git
synced 2025-12-06 08:46:52 +08:00
Compare commits
6 Commits
1cd5ab89c7
...
9f78259dab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f78259dab | ||
|
|
66d2730fa1 | ||
|
|
54f7d6d91b | ||
|
|
e3d2174b3c | ||
|
|
a6fb4d3b06 | ||
|
|
706fecea30 |
@ -493,8 +493,8 @@ template <typename OutputIt,
|
||||
#if FMT_CLANG_VERSION >= 307 && !FMT_ICC_VERSION
|
||||
__attribute__((no_sanitize("undefined")))
|
||||
#endif
|
||||
FMT_CONSTEXPR20 inline auto
|
||||
reserve(OutputIt it, size_t n) -> typename OutputIt::value_type* {
|
||||
FMT_CONSTEXPR20 inline auto reserve(OutputIt it, size_t n) ->
|
||||
typename OutputIt::value_type* {
|
||||
auto& c = get_container(it);
|
||||
size_t size = c.size();
|
||||
c.resize(size + n);
|
||||
@ -1360,14 +1360,11 @@ template <typename WChar, typename Buffer = memory_buffer> class to_utf8 {
|
||||
++p;
|
||||
if (p == s.end() || (c & 0xfc00) != 0xd800 || (*p & 0xfc00) != 0xdc00) {
|
||||
switch (policy) {
|
||||
case to_utf8_error_policy::abort:
|
||||
return false;
|
||||
case to_utf8_error_policy::abort: return false;
|
||||
case to_utf8_error_policy::replace:
|
||||
buf.append(string_view("\xEF\xBF\xBD"));
|
||||
break;
|
||||
case to_utf8_error_policy::wtf:
|
||||
to_utf8_3bytes(buf, c);
|
||||
break;
|
||||
case to_utf8_error_policy::wtf: to_utf8_3bytes(buf, c); break;
|
||||
}
|
||||
--p;
|
||||
continue;
|
||||
@ -4260,7 +4257,11 @@ class format_int {
|
||||
* // A compile-time error because 'd' is an invalid specifier for strings.
|
||||
* std::string s = fmt::format(FMT_STRING("{:d}"), "foo");
|
||||
*/
|
||||
#if FMT_USE_CONSTEVAL
|
||||
# define FMT_STRING(s) s
|
||||
#else
|
||||
# define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string)
|
||||
#endif // FMT_USE_CONSTEVAL
|
||||
|
||||
FMT_API auto vsystem_error(int error_code, string_view fmt, format_args args)
|
||||
-> std::system_error;
|
||||
|
||||
@ -90,9 +90,6 @@ TEST(compile_test, format_escape) {
|
||||
EXPECT_EQ("\"abc\" ", fmt::format(FMT_COMPILE("{0:<7?}"), "abc"));
|
||||
}
|
||||
|
||||
TEST(compile_test, format_wide_string) {
|
||||
EXPECT_EQ(L"42", fmt::format(FMT_COMPILE(L"{}"), 42));
|
||||
}
|
||||
|
||||
TEST(compile_test, format_specs) {
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{:x}"), 0x42));
|
||||
@ -124,7 +121,6 @@ TEST(compile_test, manual_ordering) {
|
||||
"true 42 42 foo 0x1234 foo",
|
||||
fmt::format(FMT_COMPILE("{0} {1} {2} {3} {4} {5}"), true, 42, 42.0f,
|
||||
"foo", reinterpret_cast<void*>(0x1234), test_formattable()));
|
||||
EXPECT_EQ(L"42", fmt::format(FMT_COMPILE(L"{0}"), 42));
|
||||
}
|
||||
|
||||
TEST(compile_test, named) {
|
||||
@ -133,10 +129,6 @@ TEST(compile_test, named) {
|
||||
static_assert(std::is_same_v<decltype(runtime_named_field_compiled),
|
||||
fmt::detail::runtime_named_field<char>>);
|
||||
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), fmt::arg("arg", 42)));
|
||||
EXPECT_EQ("41 43", fmt::format(FMT_COMPILE("{} {}"), fmt::arg("arg", 41),
|
||||
fmt::arg("arg", 43)));
|
||||
|
||||
EXPECT_EQ("foobar",
|
||||
fmt::format(FMT_COMPILE("{a0}{a1}"), fmt::arg("a0", "foo"),
|
||||
fmt::arg("a1", "bar")));
|
||||
@ -318,7 +310,6 @@ TEST(compile_test, compile_format_string_literal) {
|
||||
using namespace fmt::literals;
|
||||
EXPECT_EQ("", fmt::format(""_cf));
|
||||
EXPECT_EQ("42", fmt::format("{}"_cf, 42));
|
||||
EXPECT_EQ(L"42", fmt::format(L"{}"_cf, 42));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -2037,9 +2037,7 @@ TEST(format_test, unpacked_args) {
|
||||
}
|
||||
|
||||
constexpr char with_null[3] = {'{', '}', '\0'};
|
||||
constexpr char no_null[2] = {'{', '}'};
|
||||
static constexpr char static_with_null[3] = {'{', '}', '\0'};
|
||||
static constexpr char static_no_null[2] = {'{', '}'};
|
||||
|
||||
TEST(format_test, compile_time_string) {
|
||||
EXPECT_EQ(fmt::format(FMT_STRING("foo")), "foo");
|
||||
@ -2056,17 +2054,13 @@ TEST(format_test, compile_time_string) {
|
||||
#endif
|
||||
|
||||
(void)static_with_null;
|
||||
(void)static_no_null;
|
||||
#ifndef _MSC_VER
|
||||
EXPECT_EQ(fmt::format(FMT_STRING(static_with_null), 42), "42");
|
||||
EXPECT_EQ(fmt::format(FMT_STRING(static_no_null), 42), "42");
|
||||
#endif
|
||||
|
||||
(void)with_null;
|
||||
(void)no_null;
|
||||
#if FMT_CPLUSPLUS >= 201703L
|
||||
EXPECT_EQ(fmt::format(FMT_STRING(with_null), 42), "42");
|
||||
EXPECT_EQ(fmt::format(FMT_STRING(no_null), 42), "42");
|
||||
#endif
|
||||
#if defined(FMT_USE_STRING_VIEW) && FMT_CPLUSPLUS >= 201703L
|
||||
EXPECT_EQ(fmt::format(FMT_STRING(std::string_view("{}")), 42), "42");
|
||||
|
||||
@ -265,7 +265,7 @@ template <> struct formatter<abstract> : ostream_formatter {};
|
||||
} // namespace fmt
|
||||
|
||||
void format_abstract_compiles(const abstract& a) {
|
||||
fmt::format(FMT_COMPILE("{}"), a);
|
||||
(void)fmt::format(FMT_COMPILE("{}"), a);
|
||||
}
|
||||
|
||||
TEST(ostream_test, is_formattable) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user