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
a5f470eb
Commit
a5f470eb
authored
Aug 25, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test and fix compiled format_to_n and formatted_size
parent
4070c1d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
14 deletions
+16
-14
include/fmt/compile.h
include/fmt/compile.h
+4
-5
test/compile-test.cc
test/compile-test.cc
+12
-9
No files found.
include/fmt/compile.h
View file @
a5f470eb
...
@@ -553,16 +553,15 @@ format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
...
@@ -553,16 +553,15 @@ format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
const
CompiledFormat
&
cf
,
const
CompiledFormat
&
cf
,
const
Args
&
...
args
)
{
const
Args
&
...
args
)
{
auto
it
=
auto
it
=
cf
.
format_to
(
internal
::
truncating_iterator
<
OutputIt
>
(
out
,
n
)
,
args
...);
format_to
(
internal
::
truncating_iterator
<
OutputIt
>
(
out
,
n
),
cf
,
args
...);
return
{
it
.
base
(),
it
.
count
()};
return
{
it
.
base
(),
it
.
count
()};
}
}
template
<
typename
CompiledFormat
,
typename
...
Args
>
template
<
typename
CompiledFormat
,
typename
...
Args
>
std
::
size_t
formatted_size
(
const
CompiledFormat
&
cf
,
const
Args
&
...
args
)
{
std
::
size_t
formatted_size
(
const
CompiledFormat
&
cf
,
const
Args
&
...
args
)
{
return
cf
return
fmt
::
format_to
(
.
format_to
(
internal
::
counting_iterator
<
typename
CompiledFormat
::
char_type
>
(),
internal
::
counting_iterator
<
typename
CompiledFormat
::
char_type
>
(),
cf
,
args
...)
args
...)
.
count
();
.
count
();
}
}
...
...
test/compile-test.cc
View file @
a5f470eb
...
@@ -505,13 +505,16 @@ TEST(CompileTest, FormatToIterator) {
...
@@ -505,13 +505,16 @@ TEST(CompileTest, FormatToIterator) {
EXPECT_EQ
(
L"42"
,
ws
);
EXPECT_EQ
(
L"42"
,
ws
);
}
}
TEST
(
CompileTest
,
FormatToBackInserter
)
{
TEST
(
CompileTest
,
FormatToN
)
{
std
::
string
s
;
char
buf
[
5
];
const
auto
prepared
=
fmt
::
compile
<
int
>
(
"4{}"
);
auto
f
=
fmt
::
compile
<
int
>
(
"{:10}"
);
fmt
::
format_to
(
std
::
back_inserter
(
s
),
prepared
,
2
);
auto
result
=
fmt
::
format_to_n
(
buf
,
5
,
f
,
42
);
EXPECT_EQ
(
"42"
,
s
);
EXPECT_EQ
(
result
.
size
,
10
);
std
::
wstring
ws
;
EXPECT_EQ
(
result
.
out
,
buf
+
5
);
const
auto
wprepared
=
fmt
::
compile
<
int
>
(
L"4{}"
);
EXPECT_EQ
(
fmt
::
string_view
(
buf
,
5
),
" "
);
fmt
::
format_to
(
std
::
back_inserter
(
ws
),
wprepared
,
2
);
}
EXPECT_EQ
(
L"42"
,
ws
);
TEST
(
CompileTest
,
FormattedSize
)
{
auto
f
=
fmt
::
compile
<
int
>
(
"{:10}"
);
EXPECT_EQ
(
fmt
::
formatted_size
(
f
,
42
),
10
);
}
}
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