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