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
bf0f1075
Commit
bf0f1075
authored
Jan 28, 2017
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parameterize format_specs on character type
parent
296e9cad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
8 deletions
+29
-8
fmt/format.h
fmt/format.h
+22
-7
fmt/printf.h
fmt/printf.h
+7
-1
No files found.
fmt/format.h
View file @
bf0f1075
...
...
@@ -1739,10 +1739,13 @@ struct AlignTypeSpec : AlignSpec {
};
// Format specifiers.
class
format_specs
:
public
AlignSpec
{
template
<
typename
Char
>
class
basic_format_specs
:
public
AlignSpec
{
private:
template
<
typename
Char
>
void
set
(
fill_spec
<
Char
>
fill
)
{
template
<
typename
FillChar
>
typename
std
::
enable_if
<
std
::
is_same
<
FillChar
,
Char
>::
value
||
std
::
is_same
<
FillChar
,
char
>::
value
,
void
>::
type
set
(
fill_spec
<
FillChar
>
fill
)
{
fill_
=
fill
.
value
();
}
...
...
@@ -1765,11 +1768,11 @@ class format_specs : public AlignSpec {
int
precision_
;
char
type_
;
format_specs
(
unsigned
width
=
0
,
char
type
=
0
,
wchar_t
fill
=
' '
)
basic_
format_specs
(
unsigned
width
=
0
,
char
type
=
0
,
wchar_t
fill
=
' '
)
:
AlignSpec
(
width
,
fill
),
flags_
(
0
),
precision_
(
-
1
),
type_
(
type
)
{}
template
<
typename
...
FormatSpecs
>
explicit
format_specs
(
FormatSpecs
...
specs
)
explicit
basic_
format_specs
(
FormatSpecs
...
specs
)
:
AlignSpec
(
0
,
' '
),
flags_
(
0
),
precision_
(
-
1
),
type_
(
0
){
set
(
specs
...);
}
...
...
@@ -1779,6 +1782,8 @@ class format_specs : public AlignSpec {
char
type
()
const
{
return
type_
;
}
};
typedef
basic_format_specs
<
char
>
format_specs
;
namespace
internal
{
template
<
typename
Context
>
...
...
@@ -1853,6 +1858,9 @@ void ArgMap<Context>::init(const basic_format_args<Context> &args) {
template
<
typename
Char
>
class
ArgFormatterBase
{
public:
typedef
basic_format_specs
<
Char
>
format_specs
;
private:
basic_writer
<
Char
>
&
writer_
;
format_specs
&
spec_
;
...
...
@@ -2035,7 +2043,11 @@ class ArgFormatter : public internal::ArgFormatterBase<Char> {
private:
basic_format_context
<
Char
>
&
ctx_
;
typedef
internal
::
ArgFormatterBase
<
Char
>
Base
;
public:
typedef
typename
Base
::
format_specs
format_specs
;
/**
\rst
Constructs an argument formatter object.
...
...
@@ -2186,6 +2198,9 @@ constexpr named_format_spec<unsigned> width;
*/
template
<
typename
Char
>
class
basic_writer
{
public:
typedef
basic_format_specs
<
Char
>
format_specs
;
private:
// Output buffer.
Buffer
<
Char
>
&
buffer_
;
...
...
@@ -2461,7 +2476,7 @@ typename basic_writer<Char>::CharPtr basic_writer<Char>::write_str(
template
<
typename
Char
>
template
<
typename
StrChar
>
void
basic_writer
<
Char
>::
write_str
(
BasicStringRef
<
StrChar
>
s
,
const
format_specs
&
spec
)
{
BasicStringRef
<
StrChar
>
s
,
const
basic_writer
<
Char
>::
format_specs
&
spec
)
{
// Check if StrChar is convertible to Char.
internal
::
CharTraits
<
Char
>::
convert
(
StrChar
());
if
(
spec
.
type_
&&
spec
.
type_
!=
's'
)
...
...
@@ -3366,7 +3381,7 @@ template <typename ArgFormatter, typename Char, typename Context>
void
do_format_arg
(
basic_writer
<
Char
>
&
writer
,
basic_format_arg
<
Context
>
arg
,
Context
&
ctx
)
{
const
Char
*&
s
=
ctx
.
ptr
();
format_specs
spec
;
basic_format_specs
<
Char
>
spec
;
if
(
*
s
==
':'
)
{
if
(
visit
(
internal
::
CustomFormatter
<
Char
,
Context
>
(
writer
,
ctx
),
arg
))
return
;
...
...
fmt/printf.h
View file @
bf0f1075
...
...
@@ -168,8 +168,11 @@ class CharConverter {
// Checks if an argument is a valid printf width specifier and sets
// left alignment if it is negative.
template
<
typename
Char
>
class
PrintfWidthHandler
{
private:
typedef
basic_format_specs
<
Char
>
format_specs
;
format_specs
&
spec_
;
FMT_DISALLOW_COPY_AND_ASSIGN
(
PrintfWidthHandler
);
...
...
@@ -217,6 +220,8 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
typedef
internal
::
ArgFormatterBase
<
Char
>
Base
;
public:
typedef
typename
Base
::
format_specs
format_specs
;
/**
\rst
Constructs an argument formatter object.
...
...
@@ -301,6 +306,7 @@ class printf_context :
private:
typedef
internal
::
format_context_base
<
Char
,
printf_context
>
Base
;
typedef
typename
Base
::
format_arg
format_arg
;
typedef
basic_format_specs
<
Char
>
format_specs
;
void
parse_flags
(
format_specs
&
spec
,
const
Char
*&
s
);
...
...
@@ -396,7 +402,7 @@ unsigned printf_context<Char, AF>::parse_header(
spec
.
width_
=
internal
::
parse_nonnegative_int
(
s
);
}
else
if
(
*
s
==
'*'
)
{
++
s
;
spec
.
width_
=
visit
(
internal
::
PrintfWidthHandler
(
spec
),
get_arg
(
s
));
spec
.
width_
=
visit
(
internal
::
PrintfWidthHandler
<
Char
>
(
spec
),
get_arg
(
s
));
}
return
arg_index
;
}
...
...
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