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
18dfa257
Commit
18dfa257
authored
Oct 21, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass correct formatters to make_format_args
parent
dafbec75
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
18 deletions
+37
-18
fmt/format.h
fmt/format.h
+2
-2
fmt/ostream.h
fmt/ostream.h
+12
-7
fmt/printf.h
fmt/printf.h
+20
-6
test/custom-formatter-test.cc
test/custom-formatter-test.cc
+2
-2
test/format-test.cc
test/format-test.cc
+1
-1
No files found.
fmt/format.h
View file @
18dfa257
...
...
@@ -1494,8 +1494,8 @@ class basic_format_args {
basic_format_args
()
:
types_
(
0
)
{}
template
<
typename
F
,
typename
...
Args
>
basic_format_args
(
const
format_arg_store
<
F
,
Args
...
>
&
store
)
template
<
typename
...
Args
>
basic_format_args
(
const
format_arg_store
<
F
ormatter
,
Args
...
>
&
store
)
:
types_
(
store
.
TYPES
)
{
set_data
(
store
.
data
());
}
...
...
fmt/ostream.h
View file @
18dfa257
...
...
@@ -69,19 +69,24 @@ struct ConvertToIntImpl<T, true> {
// Write the content of w to os.
void
write
(
std
::
ostream
&
os
,
Writer
&
w
);
template
<
typename
Char
,
typename
T
>
BasicStringRef
<
Char
>
format_value
(
internal
::
MemoryBuffer
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
&
buffer
,
const
T
&
value
)
{
internal
::
FormatBuf
<
Char
>
format_buf
(
buffer
);
std
::
basic_ostream
<
Char
>
output
(
&
format_buf
);
output
<<
value
;
return
BasicStringRef
<
Char
>
(
&
buffer
[
0
],
format_buf
.
size
());
}
}
// namespace internal
// Formats a value.
template
<
typename
Char
,
typename
ArgFormatter
,
typename
T
>
void
format_value
(
BasicFormatter
<
Char
,
ArgFormatter
>
&
f
,
const
Char
*&
format_str
,
const
T
&
value
)
{
const
Char
*&
format_str
,
const
T
&
value
)
{
internal
::
MemoryBuffer
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
buffer
;
internal
::
FormatBuf
<
Char
>
format_buf
(
buffer
);
std
::
basic_ostream
<
Char
>
output
(
&
format_buf
);
output
<<
value
;
BasicStringRef
<
Char
>
str
(
&
buffer
[
0
],
format_buf
.
size
());
auto
str
=
internal
::
format_value
(
buffer
,
value
);
typedef
internal
::
MakeArg
<
BasicFormatter
<
Char
>
>
MakeArg
;
format_str
=
f
.
format
(
format_str
,
MakeArg
(
str
));
}
...
...
fmt/printf.h
View file @
18dfa257
...
...
@@ -281,9 +281,14 @@ class PrintfArgFormatter
};
/** This template formats data and writes the output to a writer. */
template
<
typename
Char
,
typename
ArgFormatter
=
PrintfArgFormatter
<
Char
>
>
template
<
typename
CharType
,
typename
ArgFormatter
=
PrintfArgFormatter
<
CharType
>
>
class
PrintfFormatter
:
private
internal
::
FormatterBase
<
PrintfFormatter
<
Char
,
ArgFormatter
>>
{
private
internal
::
FormatterBase
<
PrintfFormatter
<
CharType
,
ArgFormatter
>>
{
public:
/** The character type for the output. */
typedef
CharType
Char
;
private:
BasicWriter
<
Char
>
&
writer_
;
...
...
@@ -312,6 +317,8 @@ class PrintfFormatter :
BasicWriter
<
Char
>
&
w
)
:
Base
(
args
),
writer_
(
w
)
{}
BasicWriter
<
Char
>
&
writer
()
{
return
writer_
;
}
/** Formats stored arguments and writes the output to the writer. */
FMT_API
void
format
(
BasicCStringRef
<
Char
>
format_str
);
};
...
...
@@ -488,6 +495,13 @@ void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str) {
this
->
write
(
writer_
,
start
,
s
);
}
// Formats a value.
template
<
typename
Char
,
typename
T
>
void
format_value
(
PrintfFormatter
<
Char
>
&
f
,
const
Char
*&
,
const
T
&
value
)
{
internal
::
MemoryBuffer
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
buffer
;
f
.
writer
()
<<
internal
::
format_value
(
buffer
,
value
);
}
template
<
typename
Char
>
void
printf
(
BasicWriter
<
Char
>
&
w
,
BasicCStringRef
<
Char
>
format
,
basic_format_args
<
PrintfFormatter
<
Char
>>
args
)
{
...
...
@@ -512,7 +526,7 @@ inline std::string vsprintf(CStringRef format,
*/
template
<
typename
...
Args
>
inline
std
::
string
sprintf
(
CStringRef
format_str
,
const
Args
&
...
args
)
{
return
vsprintf
(
format_str
,
make_format_args
<
Basic
Formatter
<
char
>>
(
args
...));
return
vsprintf
(
format_str
,
make_format_args
<
Printf
Formatter
<
char
>>
(
args
...));
}
inline
std
::
wstring
vsprintf
(
WCStringRef
format
,
...
...
@@ -524,7 +538,7 @@ inline std::wstring vsprintf(WCStringRef format,
template
<
typename
...
Args
>
inline
std
::
wstring
sprintf
(
WCStringRef
format_str
,
const
Args
&
...
args
)
{
auto
vargs
=
make_format_args
<
Basic
Formatter
<
wchar_t
>>
(
args
...);
auto
vargs
=
make_format_args
<
Printf
Formatter
<
wchar_t
>>
(
args
...);
return
vsprintf
(
format_str
,
vargs
);
}
...
...
@@ -562,7 +576,7 @@ inline int vprintf(CStringRef format,
*/
template
<
typename
...
Args
>
inline
int
printf
(
CStringRef
format_str
,
const
Args
&
...
args
)
{
return
vprintf
(
format_str
,
make_format_args
<
Basic
Formatter
<
char
>>
(
args
...));
return
vprintf
(
format_str
,
make_format_args
<
Printf
Formatter
<
char
>>
(
args
...));
}
inline
int
vfprintf
(
std
::
ostream
&
os
,
CStringRef
format_str
,
...
...
@@ -585,7 +599,7 @@ inline int vfprintf(std::ostream &os, CStringRef format_str,
template
<
typename
...
Args
>
inline
int
fprintf
(
std
::
ostream
&
os
,
CStringRef
format_str
,
const
Args
&
...
args
)
{
auto
vargs
=
make_format_args
<
Basic
Formatter
<
char
>>
(
args
...);
auto
vargs
=
make_format_args
<
Printf
Formatter
<
char
>>
(
args
...);
return
vfprintf
(
os
,
format_str
,
vargs
);
}
}
// namespace fmt
...
...
test/custom-formatter-test.cc
View file @
18dfa257
...
...
@@ -58,7 +58,7 @@ std::string custom_vformat(const char *format_str,
template
<
typename
...
Args
>
std
::
string
custom_format
(
const
char
*
format_str
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_format_args
<
fmt
::
BasicFormatter
<
char
>
>
(
args
...);
auto
va
=
fmt
::
make_format_args
<
CustomFormatter
>
(
args
...);
return
custom_vformat
(
format_str
,
va
);
}
...
...
@@ -76,7 +76,7 @@ std::string custom_vsprintf(
template
<
typename
...
Args
>
std
::
string
custom_sprintf
(
const
char
*
format_str
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_format_args
<
fmt
::
BasicFormatter
<
char
>
>
(
args
...);
auto
va
=
fmt
::
make_format_args
<
CustomPrintfFormatter
>
(
args
...);
return
custom_vsprintf
(
format_str
,
va
);
}
...
...
test/format-test.cc
View file @
18dfa257
...
...
@@ -1644,7 +1644,7 @@ void custom_vformat(const char *format_str,
template
<
typename
...
Args
>
void
custom_format
(
const
char
*
format_str
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_format_args
<
fmt
::
BasicFormatter
<
char
>
>
(
args
...);
auto
va
=
fmt
::
make_format_args
<
CustomFormatter
>
(
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