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
ab054532
Commit
ab054532
authored
Jul 20, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move writer to PrintfFormatter object for consistency with BasicFormatter
parent
98236758
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
20 deletions
+19
-20
fmt/format.cc
fmt/format.cc
+2
-4
fmt/printf.h
fmt/printf.h
+14
-13
test/custom-formatter-test.cc
test/custom-formatter-test.cc
+3
-3
No files found.
fmt/format.cc
View file @
ab054532
...
@@ -521,8 +521,7 @@ template void internal::FixedBuffer<char>::grow(std::size_t);
...
@@ -521,8 +521,7 @@ template void internal::FixedBuffer<char>::grow(std::size_t);
template
void
internal
::
ArgMap
<
char
>
::
init
(
const
ArgList
&
args
);
template
void
internal
::
ArgMap
<
char
>
::
init
(
const
ArgList
&
args
);
template
void
PrintfFormatter
<
char
>
::
format
(
template
void
PrintfFormatter
<
char
>
::
format
(
CStringRef
format
);
BasicWriter
<
char
>
&
writer
,
CStringRef
format
);
template
int
internal
::
CharTraits
<
char
>
::
format_float
(
template
int
internal
::
CharTraits
<
char
>
::
format_float
(
char
*
buffer
,
std
::
size_t
size
,
const
char
*
format
,
char
*
buffer
,
std
::
size_t
size
,
const
char
*
format
,
...
@@ -538,8 +537,7 @@ template void internal::FixedBuffer<wchar_t>::grow(std::size_t);
...
@@ -538,8 +537,7 @@ template void internal::FixedBuffer<wchar_t>::grow(std::size_t);
template
void
internal
::
ArgMap
<
wchar_t
>
::
init
(
const
ArgList
&
args
);
template
void
internal
::
ArgMap
<
wchar_t
>
::
init
(
const
ArgList
&
args
);
template
void
PrintfFormatter
<
wchar_t
>
::
format
(
template
void
PrintfFormatter
<
wchar_t
>
::
format
(
WCStringRef
format
);
BasicWriter
<
wchar_t
>
&
writer
,
WCStringRef
format
);
template
int
internal
::
CharTraits
<
wchar_t
>
::
format_float
(
template
int
internal
::
CharTraits
<
wchar_t
>
::
format_float
(
wchar_t
*
buffer
,
std
::
size_t
size
,
const
wchar_t
*
format
,
wchar_t
*
buffer
,
std
::
size_t
size
,
const
wchar_t
*
format
,
...
...
fmt/printf.h
View file @
ab054532
...
@@ -255,6 +255,8 @@ template <typename Char,
...
@@ -255,6 +255,8 @@ template <typename Char,
typename
ArgFormatter
=
internal
::
PrintfArgFormatter
<
Char
>
>
typename
ArgFormatter
=
internal
::
PrintfArgFormatter
<
Char
>
>
class
PrintfFormatter
:
private
internal
::
FormatterBase
{
class
PrintfFormatter
:
private
internal
::
FormatterBase
{
private:
private:
BasicWriter
<
Char
>
&
writer_
;
void
parse_flags
(
FormatSpec
&
spec
,
const
Char
*&
s
);
void
parse_flags
(
FormatSpec
&
spec
,
const
Char
*&
s
);
// Returns the argument with specified index or, if arg_index is equal
// Returns the argument with specified index or, if arg_index is equal
...
@@ -269,15 +271,15 @@ class PrintfFormatter : private internal::FormatterBase {
...
@@ -269,15 +271,15 @@ class PrintfFormatter : private internal::FormatterBase {
public:
public:
/**
/**
\rst
\rst
Constructs a ``PrintfFormatter`` object. References to the arguments
Constructs a ``PrintfFormatter`` object. References to the arguments
and
are stored in the formatter object so make sure they have appropriat
e
the writer are stored in the formatter object so make sure they hav
e
lifetimes.
appropriate
lifetimes.
\endrst
\endrst
*/
*/
explicit
PrintfFormatter
(
const
ArgList
&
args
)
:
FormatterBase
(
args
)
{}
explicit
PrintfFormatter
(
const
ArgList
&
args
,
BasicWriter
<
Char
>
&
w
)
:
FormatterBase
(
args
),
writer_
(
w
)
{}
FMT_API
void
format
(
BasicWriter
<
Char
>
&
writer
,
FMT_API
void
format
(
BasicCStringRef
<
Char
>
format_str
);
BasicCStringRef
<
Char
>
format_str
);
};
};
template
<
typename
Char
,
typename
AF
>
template
<
typename
Char
,
typename
AF
>
...
@@ -353,19 +355,18 @@ unsigned PrintfFormatter<Char, AF>::parse_header(
...
@@ -353,19 +355,18 @@ unsigned PrintfFormatter<Char, AF>::parse_header(
}
}
template
<
typename
Char
,
typename
AF
>
template
<
typename
Char
,
typename
AF
>
void
PrintfFormatter
<
Char
,
AF
>::
format
(
void
PrintfFormatter
<
Char
,
AF
>::
format
(
BasicCStringRef
<
Char
>
format_str
)
{
BasicWriter
<
Char
>
&
writer
,
BasicCStringRef
<
Char
>
format_str
)
{
const
Char
*
start
=
format_str
.
c_str
();
const
Char
*
start
=
format_str
.
c_str
();
const
Char
*
s
=
start
;
const
Char
*
s
=
start
;
while
(
*
s
)
{
while
(
*
s
)
{
Char
c
=
*
s
++
;
Char
c
=
*
s
++
;
if
(
c
!=
'%'
)
continue
;
if
(
c
!=
'%'
)
continue
;
if
(
*
s
==
c
)
{
if
(
*
s
==
c
)
{
write
(
writer
,
start
,
s
);
write
(
writer
_
,
start
,
s
);
start
=
++
s
;
start
=
++
s
;
continue
;
continue
;
}
}
write
(
writer
,
start
,
s
-
1
);
write
(
writer
_
,
start
,
s
-
1
);
FormatSpec
spec
;
FormatSpec
spec
;
spec
.
align_
=
ALIGN_RIGHT
;
spec
.
align_
=
ALIGN_RIGHT
;
...
@@ -448,14 +449,14 @@ void PrintfFormatter<Char, AF>::format(
...
@@ -448,14 +449,14 @@ void PrintfFormatter<Char, AF>::format(
start
=
s
;
start
=
s
;
// Format argument.
// Format argument.
AF
(
writer
,
spec
).
visit
(
arg
);
AF
(
writer
_
,
spec
).
visit
(
arg
);
}
}
write
(
writer
,
start
,
s
);
write
(
writer
_
,
start
,
s
);
}
}
template
<
typename
Char
>
template
<
typename
Char
>
void
printf
(
BasicWriter
<
Char
>
&
w
,
BasicCStringRef
<
Char
>
format
,
ArgList
args
)
{
void
printf
(
BasicWriter
<
Char
>
&
w
,
BasicCStringRef
<
Char
>
format
,
ArgList
args
)
{
PrintfFormatter
<
Char
>
(
args
).
format
(
w
,
format
);
PrintfFormatter
<
Char
>
(
args
,
w
).
format
(
format
);
}
}
/**
/**
...
...
test/custom-formatter-test.cc
View file @
ab054532
...
@@ -51,10 +51,10 @@ std::string custom_format(const char *format_str, fmt::ArgList args) {
...
@@ -51,10 +51,10 @@ std::string custom_format(const char *format_str, fmt::ArgList args) {
}
}
FMT_VARIADIC
(
std
::
string
,
custom_format
,
const
char
*
)
FMT_VARIADIC
(
std
::
string
,
custom_format
,
const
char
*
)
std
::
string
custom_sprintf
(
const
char
*
fstr
,
fmt
::
ArgList
args
){
std
::
string
custom_sprintf
(
const
char
*
f
ormat_
str
,
fmt
::
ArgList
args
){
fmt
::
MemoryWriter
writer
;
fmt
::
MemoryWriter
writer
;
fmt
::
PrintfFormatter
<
char
,
CustomPAF
>
pfer
(
args
);
fmt
::
PrintfFormatter
<
char
,
CustomPAF
>
formatter
(
args
,
writer
);
pfer
.
format
(
writer
,
f
str
);
formatter
.
format
(
format_
str
);
return
writer
.
str
();
return
writer
.
str
();
}
}
FMT_VARIADIC
(
std
::
string
,
custom_sprintf
,
const
char
*
);
FMT_VARIADIC
(
std
::
string
,
custom_sprintf
,
const
char
*
);
...
...
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