Commit eddb84cf authored by Victor Zverovich's avatar Victor Zverovich

Fix formatting of exotic characters

parent 7e42c65b
......@@ -771,7 +771,7 @@ FMT_MAKE_VALUE(uint_type, unsigned char, unsigned)
template <typename C, typename Char,
FMT_ENABLE_IF(std::is_same<typename C::char_type, Char>::value)>
FMT_CONSTEXPR init<C, int, char_type> make_value(Char val) {
return val;
return {val};
}
template <typename C,
......
......@@ -2025,7 +2025,7 @@ template <typename Char, typename Handler>
FMT_CONSTEXPR const Char* parse_precision(const Char* begin, const Char* end,
Handler&& handler) {
++begin;
auto c = begin != end ? *begin : 0;
auto c = begin != end ? *begin : Char();
if ('0' <= c && c <= '9') {
handler.on_precision(parse_nonnegative_int(begin, end, handler));
} else if (c == '{') {
......@@ -2763,8 +2763,9 @@ template <typename Range> class basic_writer {
auto&& it = reserve(1);
*it++ = value;
}
void write(wchar_t value) {
static_assert(std::is_same<char_type, wchar_t>::value, "");
template <typename Char, FMT_ENABLE_IF(std::is_same<Char, char_type>::value)>
void write(Char value) {
auto&& it = reserve(1);
*it++ = value;
}
......
......@@ -2492,3 +2492,21 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) {
(void)lval;
#endif
}
struct mychar {
int value;
mychar() = default;
mychar(char val) : value(val) {}
operator int() const { return value; }
};
FMT_BEGIN_NAMESPACE
template <> struct is_char<mychar> : std::true_type {};
FMT_END_NAMESPACE
TEST(FormatTest, FormatCustomChar) {
const mychar format[] = {'{', '}', 0};
auto result = fmt::format(format, mychar('x'));
EXPECT_EQ(result.size(), 1);
EXPECT_EQ(result[0], mychar('x'));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment