mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 18:57:34 +02:00
Fix formatting of exotic characters
This commit is contained in:
@ -771,7 +771,7 @@ FMT_MAKE_VALUE(uint_type, unsigned char, unsigned)
|
|||||||
template <typename C, typename Char,
|
template <typename C, typename Char,
|
||||||
FMT_ENABLE_IF(std::is_same<typename C::char_type, Char>::value)>
|
FMT_ENABLE_IF(std::is_same<typename C::char_type, Char>::value)>
|
||||||
FMT_CONSTEXPR init<C, int, char_type> make_value(Char val) {
|
FMT_CONSTEXPR init<C, int, char_type> make_value(Char val) {
|
||||||
return val;
|
return {val};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename C,
|
template <typename C,
|
||||||
|
@ -2025,7 +2025,7 @@ template <typename Char, typename Handler>
|
|||||||
FMT_CONSTEXPR const Char* parse_precision(const Char* begin, const Char* end,
|
FMT_CONSTEXPR const Char* parse_precision(const Char* begin, const Char* end,
|
||||||
Handler&& handler) {
|
Handler&& handler) {
|
||||||
++begin;
|
++begin;
|
||||||
auto c = begin != end ? *begin : 0;
|
auto c = begin != end ? *begin : Char();
|
||||||
if ('0' <= c && c <= '9') {
|
if ('0' <= c && c <= '9') {
|
||||||
handler.on_precision(parse_nonnegative_int(begin, end, handler));
|
handler.on_precision(parse_nonnegative_int(begin, end, handler));
|
||||||
} else if (c == '{') {
|
} else if (c == '{') {
|
||||||
@ -2763,8 +2763,9 @@ template <typename Range> class basic_writer {
|
|||||||
auto&& it = reserve(1);
|
auto&& it = reserve(1);
|
||||||
*it++ = value;
|
*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);
|
auto&& it = reserve(1);
|
||||||
*it++ = value;
|
*it++ = value;
|
||||||
}
|
}
|
||||||
|
@ -2492,3 +2492,21 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) {
|
|||||||
(void)lval;
|
(void)lval;
|
||||||
#endif
|
#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'));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user