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
a5d0adf3
Commit
a5d0adf3
authored
Aug 05, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a heuristic to detect empty strftime result (#367)
parent
1a23f9c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
fmt/time.h
fmt/time.h
+7
-0
test/time-test.cc
test/time-test.cc
+4
-0
No files found.
fmt/time.h
View file @
a5d0adf3
...
...
@@ -36,6 +36,13 @@ void format(BasicFormatter<char, ArgFormatter> &f,
buffer
.
resize
(
start
+
count
);
break
;
}
if
(
size
>=
format
.
size
()
*
256
)
{
// If the buffer is 256 times larger than the format string, assume
// that `strftime` gives an empty result. There doesn't seem to be a
// better way to distinguish the two cases:
// https://github.com/fmtlib/fmt/issues/367
break
;
}
const
std
::
size_t
MIN_GROWTH
=
10
;
buffer
.
reserve
(
buffer
.
capacity
()
+
(
size
>
MIN_GROWTH
?
size
:
MIN_GROWTH
));
}
...
...
test/time-test.cc
View file @
a5d0adf3
...
...
@@ -27,3 +27,7 @@ TEST(TimeTest, GrowBuffer) {
std
::
time_t
t
=
std
::
time
(
0
);
fmt
::
format
(
s
,
*
std
::
localtime
(
&
t
));
}
TEST
(
TimeTest
,
EmptyResult
)
{
EXPECT_EQ
(
""
,
fmt
::
format
(
"{}"
,
std
::
tm
()));
}
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