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
4c721e3a
Commit
4c721e3a
authored
Apr 28, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix chrono formatting with invalid argument id (#1132)
parent
8d8ea21c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
include/fmt/chrono.h
include/fmt/chrono.h
+21
-10
test/chrono-test.cc
test/chrono-test.cc
+5
-0
No files found.
include/fmt/chrono.h
View file @
4c721e3a
...
...
@@ -585,18 +585,20 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
}
};
public:
formatter
()
:
spec
(),
precision
(
-
1
)
{}
typedef
typename
basic_parse_context
<
Char
>::
iterator
iterator
;
struct
parse_range
{
iterator
begin
;
iterator
end
;
};
FMT_CONSTEXPR
auto
parse
(
basic_parse_context
<
Char
>&
ctx
)
->
decltype
(
ctx
.
begin
())
{
FMT_CONSTEXPR
parse_range
do_parse
(
basic_parse_context
<
Char
>&
ctx
)
{
auto
begin
=
ctx
.
begin
(),
end
=
ctx
.
end
();
if
(
begin
==
end
)
return
begin
;
if
(
begin
==
end
)
return
{
begin
,
end
}
;
spec_handler
handler
{
*
this
,
ctx
,
format_str
};
begin
=
internal
::
parse_align
(
begin
,
end
,
handler
);
if
(
begin
==
end
)
return
begin
;
if
(
begin
==
end
)
return
{
begin
,
end
}
;
begin
=
internal
::
parse_width
(
begin
,
end
,
handler
);
if
(
begin
==
end
)
return
begin
;
if
(
begin
==
end
)
return
{
begin
,
end
}
;
if
(
*
begin
==
'.'
)
{
if
(
std
::
is_floating_point
<
Rep
>::
value
)
begin
=
internal
::
parse_precision
(
begin
,
end
,
handler
);
...
...
@@ -604,9 +606,18 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
handler
.
on_error
(
"precision not allowed for this argument type"
);
}
end
=
parse_chrono_format
(
begin
,
end
,
internal
::
chrono_format_checker
());
format_str
=
basic_string_view
<
Char
>
(
&*
begin
,
internal
::
to_unsigned
(
end
-
begin
));
return
end
;
return
{
begin
,
end
};
}
public:
formatter
()
:
spec
(),
precision
(
-
1
)
{}
FMT_CONSTEXPR
auto
parse
(
basic_parse_context
<
Char
>&
ctx
)
->
decltype
(
ctx
.
begin
())
{
auto
range
=
do_parse
(
ctx
);
format_str
=
basic_string_view
<
Char
>
(
&*
range
.
begin
,
internal
::
to_unsigned
(
range
.
end
-
range
.
begin
));
return
range
.
end
;
}
template
<
typename
FormatContext
>
...
...
test/chrono-test.cc
View file @
4c721e3a
...
...
@@ -296,4 +296,9 @@ TEST(ChronoTest, FormatFullSpecsQq) {
EXPECT_EQ
(
"*1.2340 ms*"
,
fmt
::
format
(
"{:*^11.4%Q %q}"
,
dms
(
1.234
)));
}
TEST
(
ChronoTest
,
InvalidWidthId
)
{
EXPECT_THROW
(
fmt
::
format
(
"{:{o}"
,
std
::
chrono
::
seconds
(
0
)),
fmt
::
format_error
);
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
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