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
5420bcce
Commit
5420bcce
authored
Nov 18, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make % an opt-in to improve compatibility with std::format
parent
56a2e207
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
9 deletions
+7
-9
include/fmt/format.h
include/fmt/format.h
+7
-0
test/format-test.cc
test/format-test.cc
+0
-9
No files found.
include/fmt/format.h
View file @
5420bcce
...
@@ -195,6 +195,11 @@ FMT_END_NAMESPACE
...
@@ -195,6 +195,11 @@ FMT_END_NAMESPACE
# define FMT_NUMERIC_ALIGN 1
# define FMT_NUMERIC_ALIGN 1
#endif
#endif
// Enable the deprecated percent specifier.
#ifndef FMT_DEPRECATED_PERCENT
# define FMT_DEPRECATED_PERCENT 0
#endif
FMT_BEGIN_NAMESPACE
FMT_BEGIN_NAMESPACE
namespace
internal
{
namespace
internal
{
...
@@ -1284,8 +1289,10 @@ FMT_CONSTEXPR float_spec parse_float_type_spec(char spec,
...
@@ -1284,8 +1289,10 @@ FMT_CONSTEXPR float_spec parse_float_type_spec(char spec,
result
.
format
=
float_format
::
fixed
;
result
.
format
=
float_format
::
fixed
;
break
;
break
;
case
'%'
:
case
'%'
:
#if FMT_DEPRECATED_PERCENT
result
.
format
=
float_format
::
fixed
;
result
.
format
=
float_format
::
fixed
;
result
.
percent
=
true
;
result
.
percent
=
true
;
#endif
break
;
break
;
case
'A'
:
case
'A'
:
result
.
upper
=
true
;
result
.
upper
=
true
;
...
...
test/format-test.cc
View file @
5420bcce
...
@@ -1202,8 +1202,6 @@ TEST(FormatterTest, Precision) {
...
@@ -1202,8 +1202,6 @@ TEST(FormatterTest, Precision) {
"precision not allowed for this argument type"
);
"precision not allowed for this argument type"
);
EXPECT_THROW_MSG
(
format
(
"{0:.2f}"
,
42ull
),
format_error
,
EXPECT_THROW_MSG
(
format
(
"{0:.2f}"
,
42ull
),
format_error
,
"precision not allowed for this argument type"
);
"precision not allowed for this argument type"
);
EXPECT_THROW_MSG
(
format
(
"{0:.2%}"
,
42
),
format_error
,
"precision not allowed for this argument type"
);
EXPECT_THROW_MSG
(
format
(
"{0:3.0}"
,
'x'
),
format_error
,
EXPECT_THROW_MSG
(
format
(
"{0:3.0}"
,
'x'
),
format_error
,
"precision not allowed for this argument type"
);
"precision not allowed for this argument type"
);
EXPECT_EQ
(
"1.2"
,
format
(
"{0:.2}"
,
1.2345
));
EXPECT_EQ
(
"1.2"
,
format
(
"{0:.2}"
,
1.2345
));
...
@@ -1488,7 +1486,6 @@ TEST(FormatterTest, FormatConvertibleToLongLong) {
...
@@ -1488,7 +1486,6 @@ TEST(FormatterTest, FormatConvertibleToLongLong) {
TEST
(
FormatterTest
,
FormatFloat
)
{
TEST
(
FormatterTest
,
FormatFloat
)
{
EXPECT_EQ
(
"392.500000"
,
format
(
"{0:f}"
,
392.5
f
));
EXPECT_EQ
(
"392.500000"
,
format
(
"{0:f}"
,
392.5
f
));
EXPECT_EQ
(
"12.500000%"
,
format
(
"{0:%}"
,
0.125
f
));
}
}
TEST
(
FormatterTest
,
FormatDouble
)
{
TEST
(
FormatterTest
,
FormatDouble
)
{
...
@@ -1501,8 +1498,6 @@ TEST(FormatterTest, FormatDouble) {
...
@@ -1501,8 +1498,6 @@ TEST(FormatterTest, FormatDouble) {
EXPECT_EQ
(
"392.65"
,
format
(
"{:G}"
,
392.65
));
EXPECT_EQ
(
"392.65"
,
format
(
"{:G}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{:f}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{:f}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{:F}"
,
392.65
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{:F}"
,
392.65
));
EXPECT_EQ
(
"12.500000%"
,
format
(
"{:%}"
,
0.125
));
EXPECT_EQ
(
"12.34%"
,
format
(
"{:.2%}"
,
0.1234432
));
char
buffer
[
BUFFER_SIZE
];
char
buffer
[
BUFFER_SIZE
];
safe_sprintf
(
buffer
,
"%e"
,
392.65
);
safe_sprintf
(
buffer
,
"%e"
,
392.65
);
EXPECT_EQ
(
buffer
,
format
(
"{0:e}"
,
392.65
));
EXPECT_EQ
(
buffer
,
format
(
"{0:e}"
,
392.65
));
...
@@ -1542,7 +1537,6 @@ TEST(FormatterTest, FormatNaN) {
...
@@ -1542,7 +1537,6 @@ TEST(FormatterTest, FormatNaN) {
EXPECT_EQ
(
"nan "
,
format
(
"{:<7}"
,
nan
));
EXPECT_EQ
(
"nan "
,
format
(
"{:<7}"
,
nan
));
EXPECT_EQ
(
" nan "
,
format
(
"{:^7}"
,
nan
));
EXPECT_EQ
(
" nan "
,
format
(
"{:^7}"
,
nan
));
EXPECT_EQ
(
" nan"
,
format
(
"{:>7}"
,
nan
));
EXPECT_EQ
(
" nan"
,
format
(
"{:>7}"
,
nan
));
EXPECT_EQ
(
"nan%"
,
format
(
"{:%}"
,
nan
));
}
}
TEST
(
FormatterTest
,
FormatInfinity
)
{
TEST
(
FormatterTest
,
FormatInfinity
)
{
...
@@ -1555,7 +1549,6 @@ TEST(FormatterTest, FormatInfinity) {
...
@@ -1555,7 +1549,6 @@ TEST(FormatterTest, FormatInfinity) {
EXPECT_EQ
(
"inf "
,
format
(
"{:<7}"
,
inf
));
EXPECT_EQ
(
"inf "
,
format
(
"{:<7}"
,
inf
));
EXPECT_EQ
(
" inf "
,
format
(
"{:^7}"
,
inf
));
EXPECT_EQ
(
" inf "
,
format
(
"{:^7}"
,
inf
));
EXPECT_EQ
(
" inf"
,
format
(
"{:>7}"
,
inf
));
EXPECT_EQ
(
" inf"
,
format
(
"{:>7}"
,
inf
));
EXPECT_EQ
(
"inf%"
,
format
(
"{:%}"
,
inf
));
}
}
TEST
(
FormatterTest
,
FormatLongDouble
)
{
TEST
(
FormatterTest
,
FormatLongDouble
)
{
...
@@ -1566,8 +1559,6 @@ TEST(FormatterTest, FormatLongDouble) {
...
@@ -1566,8 +1559,6 @@ TEST(FormatterTest, FormatLongDouble) {
EXPECT_EQ
(
"392.65"
,
format
(
"{0:G}"
,
392.65
l
));
EXPECT_EQ
(
"392.65"
,
format
(
"{0:G}"
,
392.65
l
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{0:f}"
,
392.65
l
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{0:f}"
,
392.65
l
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{0:F}"
,
392.65
l
));
EXPECT_EQ
(
"392.650000"
,
format
(
"{0:F}"
,
392.65
l
));
EXPECT_EQ
(
"12.500000%"
,
format
(
"{:%}"
,
0.125
l
));
EXPECT_EQ
(
"12.34%"
,
format
(
"{:.2%}"
,
0.1234432
l
));
char
buffer
[
BUFFER_SIZE
];
char
buffer
[
BUFFER_SIZE
];
safe_sprintf
(
buffer
,
"%Le"
,
392.65
l
);
safe_sprintf
(
buffer
,
"%Le"
,
392.65
l
);
EXPECT_EQ
(
buffer
,
format
(
"{0:e}"
,
392.65
l
));
EXPECT_EQ
(
buffer
,
format
(
"{0:e}"
,
392.65
l
));
...
...
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