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
d165d9c4
Commit
d165d9c4
authored
Dec 26, 2017
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple locale and buffer
parent
36634140
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
21 deletions
+18
-21
include/fmt/format.cc
include/fmt/format.cc
+7
-9
include/fmt/format.h
include/fmt/format.h
+11
-9
include/fmt/locale.h
include/fmt/locale.h
+0
-3
No files found.
include/fmt/format.cc
View file @
d165d9c4
...
...
@@ -220,9 +220,9 @@ void report_error(FormatFunc func, int error_code,
}
// namespace
template
<
typename
Char
>
FMT_FUNC
Char
internal
::
thousands_sep
(
const
basic_buffer
<
Char
>&
buf
)
{
return
std
::
use_facet
<
std
::
numpunct
<
Char
>>
(
buf
.
locale
().
get
())
.
thousands_sep
();
FMT_FUNC
Char
internal
::
thousands_sep
(
locale_provider
*
lp
)
{
std
::
locale
loc
=
lp
?
lp
->
locale
().
get
()
:
std
::
locale
();
return
std
::
use_facet
<
std
::
numpunct
<
Char
>>
(
loc
)
.
thousands_sep
();
}
FMT_FUNC
void
system_error
::
init
(
...
...
@@ -441,15 +441,15 @@ FMT_FUNC void vprint_colored(Color c, string_view format, format_args args) {
std
::
fputs
(
RESET_COLOR
,
stdout
);
}
FMT_FUNC
locale
locale_provider
::
locale
()
{
return
fmt
::
locale
();
}
#ifndef FMT_HEADER_ONLY
template
struct
internal
::
basic_data
<
void
>;
// Explicit instantiations for char.
template
locale
basic_buffer
<
char
>
::
locale
()
const
;
template
char
internal
::
thousands_sep
(
const
basic_buffer
<
char
>
&
buf
);
template
char
internal
::
thousands_sep
(
locale_provider
*
lp
);
template
void
basic_fixed_buffer
<
char
>
::
grow
(
std
::
size_t
);
...
...
@@ -465,9 +465,7 @@ template int internal::char_traits<char>::format_float(
// Explicit instantiations for wchar_t.
template
locale
basic_buffer
<
wchar_t
>
::
locale
()
const
;
template
wchar_t
internal
::
thousands_sep
(
const
basic_buffer
<
wchar_t
>
&
buf
);
template
wchar_t
internal
::
thousands_sep
(
locale_provider
*
lp
);
template
class
basic_context
<
wchar_t
>;
...
...
include/fmt/format.h
View file @
d165d9c4
...
...
@@ -305,11 +305,13 @@ inline T *make_ptr(T *ptr, std::size_t) { return ptr; }
// is very heavy.
class
locale
;
/**
\rst
A contiguous memory buffer with an optional growing ability.
\endrst
*/
class
locale_provider
{
public:
virtual
~
locale_provider
()
{}
virtual
locale
locale
();
};
/** A contiguous memory buffer with an optional growing ability. */
template
<
typename
T
>
class
basic_buffer
{
private:
...
...
@@ -381,8 +383,6 @@ class basic_buffer {
T
&
operator
[](
std
::
size_t
index
)
{
return
ptr_
[
index
];
}
const
T
&
operator
[](
std
::
size_t
index
)
const
{
return
ptr_
[
index
];
}
virtual
fmt
::
locale
locale
()
const
;
};
template
<
typename
T
>
...
...
@@ -868,7 +868,7 @@ class add_thousands_sep {
};
template
<
typename
Char
>
Char
thousands_sep
(
const
basic_buffer
<
Char
>&
buf
);
Char
thousands_sep
(
locale_provider
*
lp
);
// Formats a decimal unsigned integer value writing into buffer.
// thousands_sep is a functor that is called after writing each char to
...
...
@@ -2182,6 +2182,7 @@ class basic_writer {
private:
// Output buffer.
Buffer
&
buffer_
;
std
::
unique_ptr
<
locale_provider
>
locale_
;
FMT_DISALLOW_COPY_AND_ASSIGN
(
basic_writer
);
...
...
@@ -2591,7 +2592,8 @@ void basic_writer<Buffer>::write_int(T value, const Spec& spec) {
void
on_num
()
{
unsigned
num_digits
=
internal
::
count_digits
(
abs_value
);
char_type
thousands_sep
=
internal
::
thousands_sep
(
writer
.
buffer_
);
char_type
thousands_sep
=
internal
::
thousands_sep
<
char_type
>
(
writer
.
locale_
.
get
());
fmt
::
basic_string_view
<
char_type
>
sep
(
&
thousands_sep
,
1
);
unsigned
size
=
static_cast
<
unsigned
>
(
num_digits
+
sep
.
size
()
*
((
num_digits
-
1
)
/
3
));
...
...
include/fmt/locale.h
View file @
d165d9c4
...
...
@@ -19,7 +19,4 @@ class locale {
explicit
locale
(
std
::
locale
loc
=
std
::
locale
())
:
locale_
(
loc
)
{}
std
::
locale
get
()
{
return
locale_
;
}
};
template
<
typename
T
>
locale
basic_buffer
<
T
>::
locale
()
const
{
return
fmt
::
locale
();
}
}
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