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
094b66e8
Commit
094b66e8
authored
Nov 12, 2021
by
Pavel Novikov
Committed by
Victor Zverovich
Nov 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed locale retrieval way to a fancy one
parent
b69ae485
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
17 deletions
+28
-17
include/fmt/chrono.h
include/fmt/chrono.h
+28
-17
No files found.
include/fmt/chrono.h
View file @
094b66e8
...
@@ -1374,6 +1374,27 @@ OutputIt format_duration_unit(OutputIt out) {
...
@@ -1374,6 +1374,27 @@ OutputIt format_duration_unit(OutputIt out) {
return
out
;
return
out
;
}
}
struct
get_locale
{
explicit
get_locale
(
bool
localized
,
locale_ref
loc_ref
)
:
has_locale
{
localized
}
{
if
(
localized
)
::
new
(
&
locale
)
std
::
locale
{
loc_ref
.
template
get
<
std
::
locale
>()};
}
~
get_locale
()
{
if
(
has_locale
)
locale
.
~
locale
();
}
operator
const
std
::
locale
&
()
const
{
return
has_locale
?
locale
:
get_classic_locale
();
}
private:
union
{
monostate
dummy
{};
std
::
locale
locale
;
};
bool
has_locale
=
false
;
};
template
<
typename
FormatContext
,
typename
OutputIt
,
typename
Rep
,
template
<
typename
FormatContext
,
typename
OutputIt
,
typename
Rep
,
typename
Period
>
typename
Period
>
struct
chrono_formatter
{
struct
chrono_formatter
{
...
@@ -1475,14 +1496,8 @@ struct chrono_formatter {
...
@@ -1475,14 +1496,8 @@ struct chrono_formatter {
void
format_localized
(
const
tm
&
time
,
char
format
,
char
modifier
=
0
)
{
void
format_localized
(
const
tm
&
time
,
char
format
,
char
modifier
=
0
)
{
if
(
isnan
(
val
))
return
write_nan
();
if
(
isnan
(
val
))
return
write_nan
();
if
(
localized
)
{
out
=
detail
::
write
<
char_type
>
(
out
=
detail
::
write
<
char_type
>
(
out
,
time
,
get_locale
{
localized
,
context
.
locale
()},
format
,
modifier
);
out
,
time
,
context
.
locale
().
template
get
<
std
::
locale
>(),
format
,
modifier
);
}
else
{
out
=
detail
::
write
<
char_type
>
(
out
,
time
,
get_classic_locale
(),
format
,
modifier
);
}
}
}
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
...
@@ -1649,11 +1664,8 @@ template <typename Char> struct formatter<weekday, Char> {
...
@@ -1649,11 +1664,8 @@ template <typename Char> struct formatter<weekday, Char> {
auto
format
(
weekday
wd
,
FormatContext
&
ctx
)
const
->
decltype
(
ctx
.
out
())
{
auto
format
(
weekday
wd
,
FormatContext
&
ctx
)
const
->
decltype
(
ctx
.
out
())
{
auto
time
=
std
::
tm
();
auto
time
=
std
::
tm
();
time
.
tm_wday
=
static_cast
<
int
>
(
wd
.
c_encoding
());
time
.
tm_wday
=
static_cast
<
int
>
(
wd
.
c_encoding
());
if
(
localized
)
return
detail
::
write
<
Char
>
(
return
detail
::
write
<
Char
>
(
ctx
.
out
(),
time
,
ctx
.
out
(),
time
,
detail
::
get_locale
{
localized
,
ctx
.
locale
()},
'a'
);
ctx
.
locale
().
template
get
<
std
::
locale
>(),
'a'
);
return
detail
::
write
<
Char
>
(
ctx
.
out
(),
time
,
detail
::
get_classic_locale
(),
'a'
);
}
}
};
};
...
@@ -1851,10 +1863,9 @@ template <typename Char> struct formatter<std::tm, Char> {
...
@@ -1851,10 +1863,9 @@ template <typename Char> struct formatter<std::tm, Char> {
template
<
typename
FormatContext
>
template
<
typename
FormatContext
>
auto
format
(
const
std
::
tm
&
tm
,
FormatContext
&
ctx
)
const
auto
format
(
const
std
::
tm
&
tm
,
FormatContext
&
ctx
)
const
->
decltype
(
ctx
.
out
())
{
->
decltype
(
ctx
.
out
())
{
if
(
const
auto
&
loc_ref
=
ctx
.
locale
())
const
auto
loc_ref
=
ctx
.
locale
();
return
this
->
do_format
(
ctx
.
out
(),
tm
,
return
this
->
do_format
(
loc_ref
.
template
get
<
std
::
locale
>());
ctx
.
out
(),
tm
,
detail
::
get_locale
{
static_cast
<
bool
>
(
loc_ref
),
loc_ref
});
return
this
->
do_format
(
ctx
.
out
(),
tm
,
detail
::
get_classic_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