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
397e8dd9
Commit
397e8dd9
authored
Apr 15, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang-format
parent
2b415b7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
22 deletions
+24
-22
include/fmt/printf.h
include/fmt/printf.h
+9
-10
test/printf-test.cc
test/printf-test.cc
+15
-12
No files found.
include/fmt/printf.h
View file @
397e8dd9
...
...
@@ -197,8 +197,7 @@ using internal::printf; // For printing into memory_buffer.
template
<
typename
Range
>
class
printf_arg_formatter
;
template
<
typename
OutputIt
,
typename
Char
>
class
basic_printf_context
;
template
<
typename
OutputIt
,
typename
Char
>
class
basic_printf_context
;
/**
\rst
...
...
@@ -212,6 +211,7 @@ class printf_arg_formatter
public
internal
::
arg_formatter_base
<
Range
>
{
public:
typedef
decltype
(
internal
::
declval
<
Range
>
().
begin
())
iterator
;
private:
typedef
typename
Range
::
value_type
char_type
;
typedef
internal
::
arg_formatter_base
<
Range
>
base
;
...
...
@@ -326,8 +326,7 @@ template <typename T> struct printf_formatter {
};
/** This template formats data and writes the output to a writer. */
template
<
typename
OutputIt
,
typename
Char
>
class
basic_printf_context
{
template
<
typename
OutputIt
,
typename
Char
>
class
basic_printf_context
{
public:
/** The character type for the output. */
typedef
Char
char_type
;
...
...
@@ -377,14 +376,15 @@ class basic_printf_context {
}
/** Formats stored arguments and writes the output to the range. */
template
<
typename
ArgFormatter
=
printf_arg_formatter
<
back_insert_range
<
internal
::
buffer
<
Char
>
>>>
template
<
typename
ArgFormatter
=
printf_arg_formatter
<
back_insert_range
<
internal
::
buffer
<
Char
>
>>>
OutputIt
format
();
};
template
<
typename
OutputIt
,
typename
Char
>
void
basic_printf_context
<
OutputIt
,
Char
>::
parse_flags
(
format_specs
&
spec
,
const
Char
*&
it
,
const
Char
*
end
)
{
const
Char
*&
it
,
const
Char
*
end
)
{
for
(;
it
!=
end
;
++
it
)
{
switch
(
*
it
)
{
case
'-'
:
...
...
@@ -714,8 +714,8 @@ inline int vfprintf(
/** Formats arguments and writes the output to the range. */
template
<
typename
ArgFormatter
,
typename
Char
,
typename
Context
=
basic_printf_context
<
typename
ArgFormatter
::
iterator
,
Char
>
>
typename
Context
=
basic_printf_context
<
typename
ArgFormatter
::
iterator
,
Char
>
>
typename
ArgFormatter
::
iterator
vprintf
(
internal
::
buffer
<
Char
>&
out
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
Context
>
args
)
{
...
...
@@ -724,7 +724,6 @@ typename ArgFormatter::iterator vprintf(internal::buffer<Char>& out,
return
iter
;
}
/**
\rst
Prints formatted data to the stream *os*.
...
...
test/printf-test.cc
View file @
397e8dd9
...
...
@@ -556,31 +556,34 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) {
}
typedef
fmt
::
printf_arg_formatter
<
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
char
>>>
formatter_t
;
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
char
>>>
formatter_t
;
typedef
fmt
::
basic_printf_context
<
formatter_t
::
iterator
,
char
>
context_t
;
// A custom printf argument formatter that doesn't print `-` for floating-point
// values rounded to 0.
class
custom_printf_arg_formatter
:
public
formatter_t
{
public:
using
formatter_t
::
iterator
;
using
formatter_t
::
iterator
;
custom_printf_arg_formatter
(
formatter_t
::
iterator
iter
,
formatter_t
::
format_specs
&
spec
,
context_t
&
ctx
)
custom_printf_arg_formatter
(
formatter_t
::
iterator
iter
,
formatter_t
::
format_specs
&
spec
,
context_t
&
ctx
)
:
formatter_t
(
iter
,
spec
,
ctx
)
{}
using
formatter_t
::
operator
();
#if FMT_MSC_VER > 0 && FMT_MSC_VER <= 1804
template
<
typename
T
,
FMT_ENABLE_IF
(
std
::
is_floating_point
<
T
>
::
value
)
>
iterator
operator
()(
T
value
)
{
template
<
typename
T
,
FMT_ENABLE_IF
(
std
::
is_floating_point
<
T
>
::
value
)
>
iterator
operator
()(
T
value
)
{
#else
iterator
operator
()(
double
value
)
{
iterator
operator
()(
double
value
)
{
#endif
// Comparing a float to 0.0 is safe.
if
(
round
(
value
*
pow
(
10
,
spec
()
->
precision
))
==
0.0
)
value
=
0
;
return
formatter_t
::
operator
()(
value
);
}
};
// Comparing a float to 0.0 is safe.
if
(
round
(
value
*
pow
(
10
,
spec
()
->
precision
))
==
0.0
)
value
=
0
;
return
formatter_t
::
operator
()(
value
);
}
}
;
typedef
fmt
::
basic_format_args
<
context_t
>
format_args_t
;
...
...
@@ -592,7 +595,7 @@ std::string custom_vformat(fmt::string_view format_str, format_args_t args) {
template
<
typename
...
Args
>
std
::
string
custom_format
(
const
char
*
format_str
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_printf_args
(
args
...);
auto
va
=
fmt
::
make_printf_args
(
args
...);
return
custom_vformat
(
format_str
,
va
);
}
...
...
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