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
19e00887
Commit
19e00887
authored
Nov 14, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More locale support
parent
f2ee9881
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
7 deletions
+50
-7
include/fmt/format.h
include/fmt/format.h
+1
-1
include/fmt/locale.h
include/fmt/locale.h
+30
-0
test/locale-test.cc
test/locale-test.cc
+19
-6
No files found.
include/fmt/format.h
View file @
19e00887
include/fmt/locale.h
View file @
19e00887
...
...
@@ -34,6 +34,13 @@ std::basic_string<Char> vformat(
}
}
template
<
typename
S
,
typename
Char
=
FMT_CHAR
(
S
)>
inline
std
::
basic_string
<
Char
>
vformat
(
const
std
::
locale
&
loc
,
const
S
&
format_str
,
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
return
internal
::
vformat
(
loc
,
to_string_view
(
format_str
),
args
);
}
template
<
typename
S
,
typename
...
Args
>
inline
std
::
basic_string
<
FMT_CHAR
(
S
)
>
format
(
const
std
::
locale
&
loc
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
...
...
@@ -42,6 +49,29 @@ inline std::basic_string<FMT_CHAR(S)> format(
*
internal
::
checked_args
<
S
,
Args
...
>
(
format_str
,
args
...));
}
template
<
typename
String
,
typename
OutputIt
,
typename
...
Args
>
inline
typename
std
::
enable_if
<
internal
::
is_output_iterator
<
OutputIt
>::
value
,
OutputIt
>::
type
vformat_to
(
OutputIt
out
,
const
std
::
locale
&
loc
,
const
String
&
format_str
,
typename
format_args_t
<
OutputIt
,
FMT_CHAR
(
String
)
>::
type
args
)
{
typedef
output_range
<
OutputIt
,
FMT_CHAR
(
String
)
>
range
;
return
vformat_to
<
arg_formatter
<
range
>>
(
range
(
out
),
to_string_view
(
format_str
),
args
,
internal
::
locale_ref
(
loc
));
}
template
<
typename
OutputIt
,
typename
S
,
typename
...
Args
>
inline
typename
std
::
enable_if
<
internal
::
is_string
<
S
>::
value
&&
internal
::
is_output_iterator
<
OutputIt
>::
value
,
OutputIt
>::
type
format_to
(
OutputIt
out
,
const
std
::
locale
&
loc
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
typedef
typename
format_context_t
<
OutputIt
,
FMT_CHAR
(
S
)
>::
type
context
;
format_arg_store
<
context
,
Args
...
>
as
{
args
...};
return
vformat_to
(
out
,
loc
,
to_string_view
(
format_str
),
basic_format_args
<
context
>
(
as
));
}
FMT_END_NAMESPACE
#endif // FMT_LOCALE_H_
test/locale-test.cc
View file @
19e00887
...
...
@@ -8,14 +8,27 @@
#include "fmt/locale.h"
#include "gmock.h"
struct
numpunct
:
std
::
numpunct
<
char
>
{
template
<
typename
Char
>
struct
numpunct
:
std
::
numpunct
<
Char
>
{
protected:
c
har
do_thousands_sep
()
const
FMT_OVERRIDE
{
return
'~'
;
}
C
har
do_thousands_sep
()
const
FMT_OVERRIDE
{
return
'~'
;
}
};
TEST
(
LocaleTest
,
Format
)
{
std
::
locale
loc
;
EXPECT_EQ
(
"1~234~567"
,
fmt
::
format
(
std
::
locale
(
loc
,
new
numpunct
()),
"{:n}"
,
1234567
));
EXPECT_EQ
(
"1,234,567"
,
fmt
::
format
(
loc
,
"{:n}"
,
1234567
));
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
char
>
());
EXPECT_EQ
(
"1,234,567"
,
fmt
::
format
(
std
::
locale
(),
"{:n}"
,
1234567
));
EXPECT_EQ
(
"1~234~567"
,
fmt
::
format
(
loc
,
"{:n}"
,
1234567
));
fmt
::
format_arg_store
<
fmt
::
format_context
,
int
>
as
{
1234567
};
EXPECT_EQ
(
"1~234~567"
,
fmt
::
vformat
(
loc
,
"{:n}"
,
fmt
::
format_args
(
as
)));
std
::
string
s
;
fmt
::
format_to
(
std
::
back_inserter
(
s
),
loc
,
"{:n}"
,
1234567
);
EXPECT_EQ
(
"1~234~567"
,
s
);
}
TEST
(
LocaleTest
,
WFormat
)
{
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
wchar_t
>
());
EXPECT_EQ
(
L"1,234,567"
,
fmt
::
format
(
std
::
locale
(),
L"{:n}"
,
1234567
));
EXPECT_EQ
(
L"1~234~567"
,
fmt
::
format
(
loc
,
L"{:n}"
,
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
)));
}
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