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
56e63078
Commit
56e63078
authored
Jul 03, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the n specifier an opt-in
parent
31ce6bc7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
19 deletions
+22
-19
include/fmt/format.h
include/fmt/format.h
+4
-0
test/format-test.cc
test/format-test.cc
+1
-2
test/locale-test.cc
test/locale-test.cc
+16
-16
test/std-format-test.cc
test/std-format-test.cc
+1
-1
No files found.
include/fmt/format.h
View file @
56e63078
...
@@ -1234,7 +1234,9 @@ FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) {
...
@@ -1234,7 +1234,9 @@ FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) {
case
'o'
:
case
'o'
:
handler
.
on_oct
();
handler
.
on_oct
();
break
;
break
;
#ifdef FMT_DEPRECATED_N_SPECIFIER
case
'n'
:
case
'n'
:
#endif
case
'L'
:
case
'L'
:
handler
.
on_num
();
handler
.
on_num
();
break
;
break
;
...
@@ -1282,7 +1284,9 @@ FMT_CONSTEXPR float_specs parse_float_type_spec(
...
@@ -1282,7 +1284,9 @@ FMT_CONSTEXPR float_specs parse_float_type_spec(
case
'a'
:
case
'a'
:
result
.
format
=
float_format
::
hex
;
result
.
format
=
float_format
::
hex
;
break
;
break
;
#ifdef FMT_DEPRECATED_N_SPECIFIER
case
'n'
:
case
'n'
:
#endif
case
'L'
:
case
'L'
:
result
.
locale
=
true
;
result
.
locale
=
true
;
break
;
break
;
...
...
test/format-test.cc
View file @
56e63078
...
@@ -1223,7 +1223,6 @@ TEST(FormatterTest, FormatOct) {
...
@@ -1223,7 +1223,6 @@ TEST(FormatterTest, FormatOct) {
}
}
TEST
(
FormatterTest
,
FormatIntLocale
)
{
TEST
(
FormatterTest
,
FormatIntLocale
)
{
EXPECT_EQ
(
"1234"
,
format
(
"{:n}"
,
1234
));
EXPECT_EQ
(
"1234"
,
format
(
"{:L}"
,
1234
));
EXPECT_EQ
(
"1234"
,
format
(
"{:L}"
,
1234
));
}
}
...
@@ -1320,7 +1319,7 @@ TEST(FormatterTest, FormatLongDouble) {
...
@@ -1320,7 +1319,7 @@ TEST(FormatterTest, FormatLongDouble) {
}
}
TEST
(
FormatterTest
,
FormatChar
)
{
TEST
(
FormatterTest
,
FormatChar
)
{
const
char
types
[]
=
"cbBdoxX
n
L"
;
const
char
types
[]
=
"cbBdoxXL"
;
check_unknown_types
(
'a'
,
types
,
"char"
);
check_unknown_types
(
'a'
,
types
,
"char"
);
EXPECT_EQ
(
"a"
,
format
(
"{0}"
,
'a'
));
EXPECT_EQ
(
"a"
,
format
(
"{0}"
,
'a'
));
EXPECT_EQ
(
"z"
,
format
(
"{0:c}"
,
'z'
));
EXPECT_EQ
(
"z"
,
format
(
"{0:c}"
,
'z'
));
...
...
test/locale-test.cc
View file @
56e63078
...
@@ -42,50 +42,50 @@ template <typename Char> struct small_grouping : std::numpunct<Char> {
...
@@ -42,50 +42,50 @@ template <typename Char> struct small_grouping : std::numpunct<Char> {
TEST
(
LocaleTest
,
DoubleDecimalPoint
)
{
TEST
(
LocaleTest
,
DoubleDecimalPoint
)
{
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
char
>
());
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
char
>
());
EXPECT_EQ
(
"1?23"
,
fmt
::
format
(
loc
,
"{:
n
}"
,
1.23
));
EXPECT_EQ
(
"1?23"
,
fmt
::
format
(
loc
,
"{:
L
}"
,
1.23
));
}
}
TEST
(
LocaleTest
,
Format
)
{
TEST
(
LocaleTest
,
Format
)
{
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
char
>
());
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
char
>
());
EXPECT_EQ
(
"1234567"
,
fmt
::
format
(
std
::
locale
(),
"{:
n
}"
,
1234567
));
EXPECT_EQ
(
"1234567"
,
fmt
::
format
(
std
::
locale
(),
"{:
L
}"
,
1234567
));
EXPECT_EQ
(
"1~234~567"
,
fmt
::
format
(
loc
,
"{:
n
}"
,
1234567
));
EXPECT_EQ
(
"1~234~567"
,
fmt
::
format
(
loc
,
"{:
L
}"
,
1234567
));
EXPECT_EQ
(
"-1~234~567"
,
fmt
::
format
(
loc
,
"{:
n
}"
,
-
1234567
));
EXPECT_EQ
(
"-1~234~567"
,
fmt
::
format
(
loc
,
"{:
L
}"
,
-
1234567
));
fmt
::
format_arg_store
<
fmt
::
format_context
,
int
>
as
{
1234567
};
fmt
::
format_arg_store
<
fmt
::
format_context
,
int
>
as
{
1234567
};
EXPECT_EQ
(
"1~234~567"
,
fmt
::
vformat
(
loc
,
"{:
n
}"
,
fmt
::
format_args
(
as
)));
EXPECT_EQ
(
"1~234~567"
,
fmt
::
vformat
(
loc
,
"{:
L
}"
,
fmt
::
format_args
(
as
)));
std
::
string
s
;
std
::
string
s
;
fmt
::
format_to
(
std
::
back_inserter
(
s
),
loc
,
"{:
n
}"
,
1234567
);
fmt
::
format_to
(
std
::
back_inserter
(
s
),
loc
,
"{:
L
}"
,
1234567
);
EXPECT_EQ
(
"1~234~567"
,
s
);
EXPECT_EQ
(
"1~234~567"
,
s
);
std
::
locale
no_grouping_loc
(
std
::
locale
(),
new
no_grouping
<
char
>
());
std
::
locale
no_grouping_loc
(
std
::
locale
(),
new
no_grouping
<
char
>
());
EXPECT_EQ
(
"1234567"
,
fmt
::
format
(
no_grouping_loc
,
"{:
n
}"
,
1234567
));
EXPECT_EQ
(
"1234567"
,
fmt
::
format
(
no_grouping_loc
,
"{:
L
}"
,
1234567
));
std
::
locale
special_grouping_loc
(
std
::
locale
(),
new
special_grouping
<
char
>
());
std
::
locale
special_grouping_loc
(
std
::
locale
(),
new
special_grouping
<
char
>
());
EXPECT_EQ
(
"1,23,45,678"
,
fmt
::
format
(
special_grouping_loc
,
"{:
n
}"
,
12345678
));
EXPECT_EQ
(
"1,23,45,678"
,
fmt
::
format
(
special_grouping_loc
,
"{:
L
}"
,
12345678
));
std
::
locale
small_grouping_loc
(
std
::
locale
(),
new
small_grouping
<
char
>
());
std
::
locale
small_grouping_loc
(
std
::
locale
(),
new
small_grouping
<
char
>
());
EXPECT_EQ
(
"4,2,9,4,9,6,7,2,9,5"
,
EXPECT_EQ
(
"4,2,9,4,9,6,7,2,9,5"
,
fmt
::
format
(
small_grouping_loc
,
"{:
n
}"
,
max_value
<
uint32_t
>
()));
fmt
::
format
(
small_grouping_loc
,
"{:
L
}"
,
max_value
<
uint32_t
>
()));
}
}
TEST
(
LocaleTest
,
WFormat
)
{
TEST
(
LocaleTest
,
WFormat
)
{
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
wchar_t
>
());
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
wchar_t
>
());
EXPECT_EQ
(
L"1234567"
,
fmt
::
format
(
std
::
locale
(),
L"{:
n
}"
,
1234567
));
EXPECT_EQ
(
L"1234567"
,
fmt
::
format
(
std
::
locale
(),
L"{:
L
}"
,
1234567
));
EXPECT_EQ
(
L"1~234~567"
,
fmt
::
format
(
loc
,
L"{:
n
}"
,
1234567
));
EXPECT_EQ
(
L"1~234~567"
,
fmt
::
format
(
loc
,
L"{:
L
}"
,
1234567
));
fmt
::
format_arg_store
<
fmt
::
wformat_context
,
int
>
as
{
1234567
};
fmt
::
format_arg_store
<
fmt
::
wformat_context
,
int
>
as
{
1234567
};
EXPECT_EQ
(
L"1~234~567"
,
fmt
::
vformat
(
loc
,
L"{:
n
}"
,
fmt
::
wformat_args
(
as
)));
EXPECT_EQ
(
L"1~234~567"
,
fmt
::
vformat
(
loc
,
L"{:
L
}"
,
fmt
::
wformat_args
(
as
)));
EXPECT_EQ
(
L"1234567"
,
fmt
::
format
(
std
::
locale
(
"C"
),
L"{:
n
}"
,
1234567
));
EXPECT_EQ
(
L"1234567"
,
fmt
::
format
(
std
::
locale
(
"C"
),
L"{:
L
}"
,
1234567
));
std
::
locale
no_grouping_loc
(
std
::
locale
(),
new
no_grouping
<
wchar_t
>
());
std
::
locale
no_grouping_loc
(
std
::
locale
(),
new
no_grouping
<
wchar_t
>
());
EXPECT_EQ
(
L"1234567"
,
fmt
::
format
(
no_grouping_loc
,
L"{:
n
}"
,
1234567
));
EXPECT_EQ
(
L"1234567"
,
fmt
::
format
(
no_grouping_loc
,
L"{:
L
}"
,
1234567
));
std
::
locale
special_grouping_loc
(
std
::
locale
(),
std
::
locale
special_grouping_loc
(
std
::
locale
(),
new
special_grouping
<
wchar_t
>
());
new
special_grouping
<
wchar_t
>
());
EXPECT_EQ
(
L"1,23,45,678"
,
EXPECT_EQ
(
L"1,23,45,678"
,
fmt
::
format
(
special_grouping_loc
,
L"{:
n
}"
,
12345678
));
fmt
::
format
(
special_grouping_loc
,
L"{:
L
}"
,
12345678
));
std
::
locale
small_grouping_loc
(
std
::
locale
(),
new
small_grouping
<
wchar_t
>
());
std
::
locale
small_grouping_loc
(
std
::
locale
(),
new
small_grouping
<
wchar_t
>
());
EXPECT_EQ
(
L"4,2,9,4,9,6,7,2,9,5"
,
EXPECT_EQ
(
L"4,2,9,4,9,6,7,2,9,5"
,
fmt
::
format
(
small_grouping_loc
,
L"{:
n
}"
,
max_value
<
uint32_t
>
()));
fmt
::
format
(
small_grouping_loc
,
L"{:
L
}"
,
max_value
<
uint32_t
>
()));
}
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
test/std-format-test.cc
View file @
56e63078
...
@@ -62,7 +62,7 @@ TEST(StdFormatTest, Int) {
...
@@ -62,7 +62,7 @@ TEST(StdFormatTest, Int) {
string
s0
=
format
(
"{}"
,
42
);
// s0 == "42"
string
s0
=
format
(
"{}"
,
42
);
// s0 == "42"
string
s1
=
format
(
"{0:b} {0:d} {0:o} {0:x}"
,
42
);
// s1 == "101010 42 52 2a"
string
s1
=
format
(
"{0:b} {0:d} {0:o} {0:x}"
,
42
);
// s1 == "101010 42 52 2a"
string
s2
=
format
(
"{0:#x} {0:#X}"
,
42
);
// s2 == "0x2a 0X2A"
string
s2
=
format
(
"{0:#x} {0:#X}"
,
42
);
// s2 == "0x2a 0X2A"
string
s3
=
format
(
"{:
n
}"
,
1234
);
// s3 == "1234" (depends on the locale)
string
s3
=
format
(
"{:
L
}"
,
1234
);
// s3 == "1234" (depends on the locale)
EXPECT_EQ
(
s0
,
"42"
);
EXPECT_EQ
(
s0
,
"42"
);
EXPECT_EQ
(
s1
,
"101010 42 52 2a"
);
EXPECT_EQ
(
s1
,
"101010 42 52 2a"
);
EXPECT_EQ
(
s2
,
"0x2a 0X2A"
);
EXPECT_EQ
(
s2
,
"0x2a 0X2A"
);
...
...
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