mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-05 09:40:40 +00:00
Ranges wide strings support (#2236)
* Ranges copy wchar_t * arg_join formatter not working for wide strings * Added ranges wide string tests Co-authored-by: Cristi <cristi@emailaddressmanager.com>
This commit is contained in:
parent
24c9751558
commit
9260114162
@ -3720,7 +3720,7 @@ struct formatter<arg_join<It, Sentinel, Char>, Char> {
|
|||||||
private:
|
private:
|
||||||
using value_type = typename std::iterator_traits<It>::value_type;
|
using value_type = typename std::iterator_traits<It>::value_type;
|
||||||
using formatter_type =
|
using formatter_type =
|
||||||
conditional_t<has_formatter<value_type, format_context>::value,
|
conditional_t<has_formatter<value_type, buffer_context<Char>>::value,
|
||||||
formatter<value_type, Char>,
|
formatter<value_type, Char>,
|
||||||
detail::fallback_formatter<value_type, Char>>;
|
detail::fallback_formatter<value_type, Char>>;
|
||||||
|
|
||||||
|
@ -67,6 +67,12 @@ OutputIterator copy(char ch, OutputIterator out) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename OutputIterator>
|
||||||
|
OutputIterator copy(wchar_t ch, OutputIterator out) {
|
||||||
|
*out++ = ch;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/// Return true value if T has std::string interface, like std::string_view.
|
/// Return true value if T has std::string interface, like std::string_view.
|
||||||
template <typename T> class is_like_std_string {
|
template <typename T> class is_like_std_string {
|
||||||
template <typename U>
|
template <typename U>
|
||||||
|
@ -224,6 +224,25 @@ TEST(RangesTest, JoinTuple) {
|
|||||||
EXPECT_EQ("4", fmt::format("{}", fmt::join(t4, "/")));
|
EXPECT_EQ("4", fmt::format("{}", fmt::join(t4, "/")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(RangesTest, WideStringJoinTuple) {
|
||||||
|
// Value tuple args
|
||||||
|
std::tuple<wchar_t, int, float> t1 = std::make_tuple('a', 1, 2.0f);
|
||||||
|
EXPECT_EQ(L"(a, 1, 2)", fmt::format(L"({})", fmt::join(t1, L", ")));
|
||||||
|
|
||||||
|
// Testing lvalue tuple args
|
||||||
|
int x = 4;
|
||||||
|
std::tuple<wchar_t, int&> t2{'b', x};
|
||||||
|
EXPECT_EQ(L"b + 4", fmt::format(L"{}", fmt::join(t2, L" + ")));
|
||||||
|
|
||||||
|
// Empty tuple
|
||||||
|
std::tuple<> t3;
|
||||||
|
EXPECT_EQ(L"", fmt::format(L"{}", fmt::join(t3, L"|")));
|
||||||
|
|
||||||
|
// Single element tuple
|
||||||
|
std::tuple<float> t4{4.0f};
|
||||||
|
EXPECT_EQ(L"4", fmt::format(L"{}", fmt::join(t4, L"/")));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(RangesTest, JoinInitializerList) {
|
TEST(RangesTest, JoinInitializerList) {
|
||||||
EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join({1, 2, 3}, ", ")));
|
EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join({1, 2, 3}, ", ")));
|
||||||
EXPECT_EQ("fmt rocks !",
|
EXPECT_EQ("fmt rocks !",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user