Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quotes for string support. #763

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
df46ef0
Add support for ranges, containers and types tuple interface in fmt/r…
Remotion May 10, 2018
50ee89b
Removed string_view
Remotion May 10, 2018
951b743
Fix docs, take 2
vitaut May 12, 2018
a442c77
Changes code style to Google Style.
Remotion May 12, 2018
5717bd2
Merge branch 'master' of https://github.com/fmtlib/fmt
Remotion May 12, 2018
4cfc6c4
Using FMT_BEGIN_NAMESPACE and FMT_END_NAMESPACE now.
Remotion May 12, 2018
648b937
Fixed build.py conflict.
Remotion May 12, 2018
f101d62
Fixed typo.
Remotion May 12, 2018
7a2099e
Using FMT_CONSTEXPR_DECL for variables.
Remotion May 12, 2018
a7041e9
Merge branch 'master' of https://github.com/fmtlib/fmt
Remotion May 12, 2018
a70b480
Moved range_length_limit to formatting_range.
Remotion May 13, 2018
d2ef18c
Merge branch 'master' of https://github.com/fmtlib/fmt
Remotion May 13, 2018
f65bcb8
Updated ranges-test.cc.
Remotion May 13, 2018
b607de8
Merge branch 'master' of https://github.com/fmtlib/fmt
Remotion May 18, 2018
3e9c0d5
Merge branch 'master' of https://github.com/fmtlib/fmt
Remotion May 20, 2018
48415bc
Merge branch 'master' of https://github.com/fmtlib/fmt
Remotion May 21, 2018
25c783f
Merge branch 'master' of https://github.com/fmtlib/fmt
Remotion Jun 6, 2018
becd39a
Added format_str_quoted.
Remotion Jun 6, 2018
eed4a77
Fixes for format_str_quoted.
Remotion Jun 6, 2018
0f06f51
Fixed ranges test.
Remotion Jun 6, 2018
9091637
Use FMT_CONSTEXPR instate of inline.
Remotion Jun 6, 2018
9a53c1f
Merged latest commit.
Remotion Jun 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,33 @@ void for_each(Tuple &&tup, F &&f) {
const auto indexes = get_indexes(tup);
for_each(indexes, std::forward<Tuple>(tup), std::forward<F>(f));
}

template<typename Arg>
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const Arg&,
typename std::enable_if<!is_like_std_string<typename std::decay<Arg>::type>::value>::type* = nullptr) {
return add_space ? " {}" : "{}";
}

template<typename Arg>
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const Arg&,
typename std::enable_if<is_like_std_string<typename std::decay<Arg>::type>::value>::type* = nullptr) {
return add_space ? " '{}'" : "'{}'";
}

FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const char*) {
return add_space ? " '{}'" : "'{}'";
}
FMT_CONSTEXPR const wchar_t* format_str_quoted(bool add_space, const wchar_t*) {
return add_space ? L" '{}'" : L"'{}'";
}

FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const char) {
return add_space ? " '{}'" : "'{}'";
}
FMT_CONSTEXPR const wchar_t* format_str_quoted(bool add_space, const wchar_t) {
return add_space ? L" '{}'" : L"'{}'";
}

} // namespace internal

template <typename T>
Expand All @@ -185,11 +212,7 @@ struct formatter<TupleT, Char,
}
internal::copy(formatting.delimiter, out);
}
if (formatting.add_delimiter_spaces && i > 0) {
format_to(out, " {}", v);
} else {
format_to(out, "{}", v);
}
format_to(out, internal::format_str_quoted((formatting.add_delimiter_spaces && i > 0), v), v);
++i;
}

Expand Down Expand Up @@ -252,11 +275,7 @@ struct formatter<RangeT, Char,
}
internal::copy(formatting.delimiter, out);
}
if (formatting.add_delimiter_spaces && i > 0) {
format_to(out, " {}", *it);
} else {
format_to(out, "{}", *it);
}
format_to(out, internal::format_str_quoted((formatting.add_delimiter_spaces && i > 0), *it), *it);
if (++i > formatting.range_length_limit) {
format_to(out, " ... <other elements>");
break;
Expand Down
6 changes: 3 additions & 3 deletions test/ranges-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST(RangesTest, FormatVector2) {

TEST(RangesTest, FormatMap) {
std::map<std::string, int32_t> simap{{"one", 1}, {"two", 2}};
EXPECT_EQ("{(one, 1), (two, 2)}", fmt::format("{}", simap));
EXPECT_EQ("{('one', 1), ('two', 2)}", fmt::format("{}", simap));
}

TEST(RangesTest, FormatPair) {
Expand All @@ -43,7 +43,7 @@ TEST(RangesTest, FormatPair) {
TEST(RangesTest, FormatTuple) {
std::tuple<int64_t, float, std::string> tu1{42, 3.14159265358979f,
"this is tuple"};
EXPECT_EQ("(42, 3.14159, this is tuple)", fmt::format("{}", tu1));
EXPECT_EQ("(42, 3.14159, 'this is tuple')", fmt::format("{}", tu1));
}

/// Check if 'if constexpr' is supported.
Expand Down Expand Up @@ -81,7 +81,7 @@ struct tuple_element<N, my_struct> {

TEST(RangesTest, FormatStruct) {
my_struct mst{13, "my struct"};
EXPECT_EQ("(13, my struct)", fmt::format("{}", mst));
EXPECT_EQ("(13, 'my struct')", fmt::format("{}", mst));
}

#endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >
Expand Down