mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 11:14:41 +00:00
Handle exotic character types in compilation
This commit is contained in:
parent
f674434a67
commit
1d696dc280
@ -637,9 +637,13 @@ template <typename S, typename... Args,
|
|||||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||||
FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
|
FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
|
||||||
Args&&... args) {
|
Args&&... args) {
|
||||||
constexpr basic_string_view<typename S::char_type> str = S();
|
#ifdef __cpp_if_constexpr
|
||||||
if (str.size() == 2 && str[0] == '{' && str[1] == '}')
|
if constexpr (std::is_same<typename S::char_type, char>::value) {
|
||||||
return fmt::to_string(detail::first(args...));
|
constexpr basic_string_view<typename S::char_type> str = S();
|
||||||
|
if (str.size() == 2 && str[0] == '{' && str[1] == '}')
|
||||||
|
return fmt::to_string(detail::first(args...));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
constexpr auto compiled = detail::compile<Args...>(S());
|
constexpr auto compiled = detail::compile<Args...>(S());
|
||||||
return format(compiled, std::forward<Args>(args)...);
|
return format(compiled, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,10 @@ TEST(CompileTest, FormatDefault) {
|
|||||||
EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), test_formattable()));
|
EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), test_formattable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CompileTest, FormatWideString) {
|
||||||
|
EXPECT_EQ(L"42", fmt::format(FMT_COMPILE(L"{}"), 42));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(CompileTest, FormatSpecs) {
|
TEST(CompileTest, FormatSpecs) {
|
||||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{:x}"), 0x42));
|
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{:x}"), 0x42));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user