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
ddd7caf3
Commit
ddd7caf3
authored
Oct 13, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix locale-dependent formatting (#905)
parent
10e03e69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
include/fmt/format.h
include/fmt/format.h
+10
-4
test/format-test.cc
test/format-test.cc
+2
-0
No files found.
include/fmt/format.h
View file @
ddd7caf3
...
...
@@ -988,6 +988,8 @@ struct no_thousands_sep {
template
<
typename
Char
>
void
operator
()(
Char
*
)
{}
enum
{
size
=
0
};
};
// A functor that adds a thousands separator.
...
...
@@ -1012,6 +1014,8 @@ class add_thousands_sep {
std
::
uninitialized_copy
(
sep_
.
data
(),
sep_
.
data
()
+
sep_
.
size
(),
internal
::
make_checked
(
buffer
,
sep_
.
size
()));
}
enum
{
size
=
1
};
};
template
<
typename
Char
>
...
...
@@ -1052,10 +1056,12 @@ template <typename OutChar, typename UInt, typename Iterator,
inline
Iterator
format_decimal
(
Iterator
out
,
UInt
value
,
unsigned
num_digits
,
ThousandsSep
sep
)
{
typedef
typename
ThousandsSep
::
char_type
char_type
;
// Buffer should be large enough to hold all digits (digits10 + 1) and null.
char_type
buffer
[
std
::
numeric_limits
<
UInt
>::
digits10
+
2
];
format_decimal
(
buffer
,
value
,
num_digits
,
sep
);
return
internal
::
copy_str
<
OutChar
>
(
buffer
,
buffer
+
num_digits
,
out
);
// Buffer should be large enough to hold all digits (<= digits10 + 1).
enum
{
max_size
=
std
::
numeric_limits
<
UInt
>::
digits10
+
1
};
FMT_ASSERT
(
ThousandsSep
::
size
<=
1
,
"invalid separator"
);
char_type
buffer
[
max_size
+
max_size
/
3
];
auto
end
=
format_decimal
(
buffer
,
value
,
num_digits
,
sep
);
return
internal
::
copy_str
<
OutChar
>
(
buffer
,
end
,
out
);
}
template
<
typename
OutChar
,
typename
It
,
typename
UInt
>
...
...
test/format-test.cc
View file @
ddd7caf3
...
...
@@ -1378,6 +1378,8 @@ TEST(FormatterTest, FormatIntLocale) {
EXPECT_EQ
(
"123"
,
format
(
"{:n}"
,
123
));
EXPECT_EQ
(
"1,234"
,
format
(
"{:n}"
,
1234
));
EXPECT_EQ
(
"1,234,567"
,
format
(
"{:n}"
,
1234567
));
EXPECT_EQ
(
"4,294,967,295"
,
format
(
"{:n}"
,
std
::
numeric_limits
<
uint32_t
>::
max
()));
}
struct
ConvertibleToLongLong
{
...
...
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