Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
d2bfee13
Commit
d2bfee13
authored
Jun 07, 2018
by
Remotion
Committed by
Victor Zverovich
Jun 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added quotes for strings in ranges and tuple likes.
parent
1b8a7f8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
15 deletions
+34
-15
include/fmt/ranges.h
include/fmt/ranges.h
+29
-10
test/ranges-test.cc
test/ranges-test.cc
+5
-5
No files found.
include/fmt/ranges.h
View file @
d2bfee13
...
@@ -162,6 +162,33 @@ void for_each(Tuple &&tup, F &&f) {
...
@@ -162,6 +162,33 @@ void for_each(Tuple &&tup, F &&f) {
const
auto
indexes
=
get_indexes
(
tup
);
const
auto
indexes
=
get_indexes
(
tup
);
for_each
(
indexes
,
std
::
forward
<
Tuple
>
(
tup
),
std
::
forward
<
F
>
(
f
));
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
}
// namespace internal
template
<
typename
T
>
template
<
typename
T
>
...
@@ -185,11 +212,7 @@ private:
...
@@ -185,11 +212,7 @@ private:
}
}
internal
::
copy
(
formatting
.
delimiter
,
out
);
internal
::
copy
(
formatting
.
delimiter
,
out
);
}
}
if
(
formatting
.
add_delimiter_spaces
&&
i
>
0
)
{
format_to
(
out
,
internal
::
format_str_quoted
((
formatting
.
add_delimiter_spaces
&&
i
>
0
),
v
),
v
);
format_to
(
out
,
" {}"
,
v
);
}
else
{
format_to
(
out
,
"{}"
,
v
);
}
++
i
;
++
i
;
}
}
...
@@ -252,11 +275,7 @@ struct formatter<RangeT, Char,
...
@@ -252,11 +275,7 @@ struct formatter<RangeT, Char,
}
}
internal
::
copy
(
formatting
.
delimiter
,
out
);
internal
::
copy
(
formatting
.
delimiter
,
out
);
}
}
if
(
formatting
.
add_delimiter_spaces
&&
i
>
0
)
{
format_to
(
out
,
internal
::
format_str_quoted
((
formatting
.
add_delimiter_spaces
&&
i
>
0
),
*
it
),
*
it
);
format_to
(
out
,
" {}"
,
*
it
);
}
else
{
format_to
(
out
,
"{}"
,
*
it
);
}
if
(
++
i
>
formatting
.
range_length_limit
)
{
if
(
++
i
>
formatting
.
range_length_limit
)
{
format_to
(
out
,
" ... <other elements>"
);
format_to
(
out
,
" ... <other elements>"
);
break
;
break
;
...
...
test/ranges-test.cc
View file @
d2bfee13
...
@@ -32,7 +32,7 @@ TEST(RangesTest, FormatVector2) {
...
@@ -32,7 +32,7 @@ TEST(RangesTest, FormatVector2) {
TEST
(
RangesTest
,
FormatMap
)
{
TEST
(
RangesTest
,
FormatMap
)
{
std
::
map
<
std
::
string
,
int32_t
>
simap
{{
"one"
,
1
},
{
"two"
,
2
}};
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
)
{
TEST
(
RangesTest
,
FormatPair
)
{
...
@@ -41,9 +41,9 @@ TEST(RangesTest, FormatPair) {
...
@@ -41,9 +41,9 @@ TEST(RangesTest, FormatPair) {
}
}
TEST
(
RangesTest
,
FormatTuple
)
{
TEST
(
RangesTest
,
FormatTuple
)
{
std
::
tuple
<
int64_t
,
float
,
std
::
string
>
tu1
{
42
,
3.14159265358979
f
,
std
::
tuple
<
int64_t
,
float
,
std
::
string
,
char
>
tu1
{
42
,
3.14159265358979
f
,
"this is tuple"
};
"this is tuple"
,
'i'
};
EXPECT_EQ
(
"(42, 3.14159,
this is tuple
)"
,
fmt
::
format
(
"{}"
,
tu1
));
EXPECT_EQ
(
"(42, 3.14159,
\"
this is tuple
\"
, 'i'
)"
,
fmt
::
format
(
"{}"
,
tu1
));
}
}
/// Check if 'if constexpr' is supported.
/// Check if 'if constexpr' is supported.
...
@@ -81,7 +81,7 @@ struct tuple_element<N, my_struct> {
...
@@ -81,7 +81,7 @@ struct tuple_element<N, my_struct> {
TEST
(
RangesTest
,
FormatStruct
)
{
TEST
(
RangesTest
,
FormatStruct
)
{
my_struct
mst
{
13
,
"my struct"
};
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 >
#endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment