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
0508bbc7
Commit
0508bbc7
authored
Jun 13, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add wchar_t overload of format_to_n (#764)
parent
c2fbadb9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
include/fmt/format.h
include/fmt/format.h
+16
-1
test/format-test.cc
test/format-test.cc
+9
-0
No files found.
include/fmt/format.h
View file @
0508bbc7
...
@@ -3526,6 +3526,13 @@ inline OutputIt vformat_to(OutputIt out, string_view format_str,
...
@@ -3526,6 +3526,13 @@ inline OutputIt vformat_to(OutputIt out, string_view format_str,
typedef
output_range
<
OutputIt
,
char
>
range
;
typedef
output_range
<
OutputIt
,
char
>
range
;
return
vformat_to
<
arg_formatter
<
range
>>
(
range
(
out
),
format_str
,
args
);
return
vformat_to
<
arg_formatter
<
range
>>
(
range
(
out
),
format_str
,
args
);
}
}
template
<
typename
OutputIt
,
typename
...
Args
>
inline
OutputIt
vformat_to
(
OutputIt
out
,
wstring_view
format_str
,
typename
format_args_t
<
OutputIt
,
wchar_t
>::
type
args
)
{
typedef
output_range
<
OutputIt
,
wchar_t
>
range
;
return
vformat_to
<
arg_formatter
<
range
>>
(
range
(
out
),
format_str
,
args
);
}
/**
/**
\rst
\rst
...
@@ -3578,12 +3585,20 @@ struct format_to_n_result {
...
@@ -3578,12 +3585,20 @@ struct format_to_n_result {
*/
*/
template
<
typename
OutputIt
,
typename
...
Args
>
template
<
typename
OutputIt
,
typename
...
Args
>
inline
format_to_n_result
<
OutputIt
>
format_to_n
(
inline
format_to_n_result
<
OutputIt
>
format_to_n
(
OutputIt
out
,
std
::
size_t
n
,
string_view
format_str
,
const
Args
&
...
args
)
{
OutputIt
out
,
std
::
size_t
n
,
string_view
format_str
,
const
Args
&
...
args
)
{
typedef
internal
::
truncating_iterator
<
OutputIt
>
It
;
typedef
internal
::
truncating_iterator
<
OutputIt
>
It
;
auto
it
=
vformat_to
(
It
(
out
,
n
),
format_str
,
auto
it
=
vformat_to
(
It
(
out
,
n
),
format_str
,
make_format_args
<
typename
format_context_t
<
It
>::
type
>
(
args
...));
make_format_args
<
typename
format_context_t
<
It
>::
type
>
(
args
...));
return
{
it
.
base
(),
it
.
count
()};
return
{
it
.
base
(),
it
.
count
()};
}
}
template
<
typename
OutputIt
,
typename
...
Args
>
inline
format_to_n_result
<
OutputIt
>
format_to_n
(
OutputIt
out
,
std
::
size_t
n
,
wstring_view
format_str
,
const
Args
&
...
args
)
{
typedef
internal
::
truncating_iterator
<
OutputIt
>
It
;
auto
it
=
vformat_to
(
It
(
out
,
n
),
format_str
,
make_format_args
<
typename
format_context_t
<
It
,
wchar_t
>::
type
>
(
args
...));
return
{
it
.
base
(),
it
.
count
()};
}
inline
std
::
string
vformat
(
string_view
format_str
,
format_args
args
)
{
inline
std
::
string
vformat
(
string_view
format_str
,
format_args
args
)
{
memory_buffer
buffer
;
memory_buffer
buffer
;
...
...
test/format-test.cc
View file @
0508bbc7
...
@@ -1525,6 +1525,15 @@ TEST(FormatTest, FormatToN) {
...
@@ -1525,6 +1525,15 @@ TEST(FormatTest, FormatToN) {
EXPECT_EQ
(
"foox"
,
fmt
::
string_view
(
buffer
,
4
));
EXPECT_EQ
(
"foox"
,
fmt
::
string_view
(
buffer
,
4
));
}
}
TEST
(
FormatTest
,
WideFormatToN
)
{
wchar_t
buffer
[
4
];
buffer
[
3
]
=
L'x'
;
auto
result
=
fmt
::
format_to_n
(
buffer
,
3
,
L"{}"
,
12345
);
EXPECT_EQ
(
5u
,
result
.
size
);
EXPECT_EQ
(
buffer
+
3
,
result
.
out
);
EXPECT_EQ
(
L"123x"
,
fmt
::
wstring_view
(
buffer
,
4
));
}
#if FMT_USE_CONSTEXPR
#if FMT_USE_CONSTEXPR
struct
test_arg_id_handler
{
struct
test_arg_id_handler
{
enum
result
{
NONE
,
EMPTY
,
INDEX
,
NAME
,
ERROR
};
enum
result
{
NONE
,
EMPTY
,
INDEX
,
NAME
,
ERROR
};
...
...
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