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
0a96c032
Commit
0a96c032
authored
Oct 25, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parameterize v*printf on string type (#920)
parent
61e6d2e3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
27 deletions
+37
-27
include/fmt/core.h
include/fmt/core.h
+1
-1
include/fmt/format-inl.h
include/fmt/format-inl.h
+3
-3
include/fmt/format.h
include/fmt/format.h
+4
-4
include/fmt/ostream.h
include/fmt/ostream.h
+1
-1
include/fmt/printf.h
include/fmt/printf.h
+18
-18
test/printf-test.cc
test/printf-test.cc
+10
-0
No files found.
include/fmt/core.h
View file @
0a96c032
...
@@ -1398,7 +1398,7 @@ typename std::enable_if<
...
@@ -1398,7 +1398,7 @@ typename std::enable_if<
const
S
&
format_str
,
const
S
&
format_str
,
basic_format_args
<
typename
buffer_context
<
FMT_CHAR
(
S
)
>::
type
>
args
)
{
basic_format_args
<
typename
buffer_context
<
FMT_CHAR
(
S
)
>::
type
>
args
)
{
internal
::
container_buffer
<
Container
>
buf
(
internal
::
get_container
(
out
));
internal
::
container_buffer
<
Container
>
buf
(
internal
::
get_container
(
out
));
vformat_to
(
buf
,
to_string_view
(
format_str
),
args
);
internal
::
vformat_to
(
buf
,
to_string_view
(
format_str
),
args
);
return
out
;
return
out
;
}
}
...
...
include/fmt/format-inl.h
View file @
0a96c032
...
@@ -943,14 +943,14 @@ FMT_FUNC void report_windows_error(
...
@@ -943,14 +943,14 @@ FMT_FUNC void report_windows_error(
FMT_FUNC
void
vprint
(
std
::
FILE
*
f
,
string_view
format_str
,
format_args
args
)
{
FMT_FUNC
void
vprint
(
std
::
FILE
*
f
,
string_view
format_str
,
format_args
args
)
{
memory_buffer
buffer
;
memory_buffer
buffer
;
vformat_to
(
buffer
,
format_str
,
internal
::
vformat_to
(
buffer
,
format_str
,
basic_format_args
<
buffer_context
<
char
>::
type
>
(
args
));
basic_format_args
<
buffer_context
<
char
>::
type
>
(
args
));
std
::
fwrite
(
buffer
.
data
(),
1
,
buffer
.
size
(),
f
);
std
::
fwrite
(
buffer
.
data
(),
1
,
buffer
.
size
(),
f
);
}
}
FMT_FUNC
void
vprint
(
std
::
FILE
*
f
,
wstring_view
format_str
,
wformat_args
args
)
{
FMT_FUNC
void
vprint
(
std
::
FILE
*
f
,
wstring_view
format_str
,
wformat_args
args
)
{
wmemory_buffer
buffer
;
wmemory_buffer
buffer
;
vformat_to
(
buffer
,
format_str
,
args
);
internal
::
vformat_to
(
buffer
,
format_str
,
args
);
std
::
fwrite
(
buffer
.
data
(),
sizeof
(
wchar_t
),
buffer
.
size
(),
f
);
std
::
fwrite
(
buffer
.
data
(),
sizeof
(
wchar_t
),
buffer
.
size
(),
f
);
}
}
...
...
include/fmt/format.h
View file @
0a96c032
...
@@ -3378,7 +3378,7 @@ template <typename S, typename Char = FMT_CHAR(S)>
...
@@ -3378,7 +3378,7 @@ template <typename S, typename Char = FMT_CHAR(S)>
inline
typename
buffer_context
<
Char
>::
type
::
iterator
vformat_to
(
inline
typename
buffer_context
<
Char
>::
type
::
iterator
vformat_to
(
internal
::
basic_buffer
<
Char
>
&
buf
,
const
S
&
format_str
,
internal
::
basic_buffer
<
Char
>
&
buf
,
const
S
&
format_str
,
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
return
vformat_to
(
buf
,
to_string_view
(
format_str
),
args
);
return
internal
::
vformat_to
(
buf
,
to_string_view
(
format_str
),
args
);
}
}
template
<
template
<
...
@@ -3391,8 +3391,8 @@ inline typename buffer_context<Char>::type::iterator format_to(
...
@@ -3391,8 +3391,8 @@ inline typename buffer_context<Char>::type::iterator format_to(
internal
::
check_format_string
<
Args
...
>
(
format_str
);
internal
::
check_format_string
<
Args
...
>
(
format_str
);
typedef
typename
buffer_context
<
Char
>::
type
context
;
typedef
typename
buffer_context
<
Char
>::
type
context
;
format_arg_store
<
context
,
Args
...
>
as
{
args
...};
format_arg_store
<
context
,
Args
...
>
as
{
args
...};
return
vformat_to
(
buf
,
to_string_view
(
format_str
),
return
internal
::
vformat_to
(
buf
,
to_string_view
(
format_str
),
basic_format_args
<
context
>
(
as
));
basic_format_args
<
context
>
(
as
));
}
}
template
<
typename
OutputIt
,
typename
Char
=
char
>
template
<
typename
OutputIt
,
typename
Char
=
char
>
...
@@ -3495,7 +3495,7 @@ inline std::basic_string<Char> internal::vformat(
...
@@ -3495,7 +3495,7 @@ inline std::basic_string<Char> internal::vformat(
basic_string_view
<
Char
>
format_str
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
basic_memory_buffer
<
Char
>
buffer
;
vformat_to
(
buffer
,
format_str
,
args
);
internal
::
vformat_to
(
buffer
,
format_str
,
args
);
return
fmt
::
to_string
(
buffer
);
return
fmt
::
to_string
(
buffer
);
}
}
...
...
include/fmt/ostream.h
View file @
0a96c032
...
@@ -129,7 +129,7 @@ inline void vprint(std::basic_ostream<Char> &os,
...
@@ -129,7 +129,7 @@ inline void vprint(std::basic_ostream<Char> &os,
basic_string_view
<
Char
>
format_str
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
basic_memory_buffer
<
Char
>
buffer
;
vformat_to
(
buffer
,
format_str
,
args
);
internal
::
vformat_to
(
buffer
,
format_str
,
args
);
internal
::
write
(
os
,
buffer
);
internal
::
write
(
os
,
buffer
);
}
}
/**
/**
...
...
include/fmt/printf.h
View file @
0a96c032
...
@@ -580,13 +580,13 @@ struct printf_context {
...
@@ -580,13 +580,13 @@ struct printf_context {
typedef
basic_format_args
<
printf_context
<
internal
::
buffer
>::
type
>
printf_args
;
typedef
basic_format_args
<
printf_context
<
internal
::
buffer
>::
type
>
printf_args
;
typedef
basic_format_args
<
printf_context
<
internal
::
wbuffer
>::
type
>
wprintf_args
;
typedef
basic_format_args
<
printf_context
<
internal
::
wbuffer
>::
type
>
wprintf_args
;
template
<
typename
Char
>
template
<
typename
S
,
typename
Char
=
FMT_CHAR
(
S
)
>
inline
std
::
basic_string
<
Char
>
inline
std
::
basic_string
<
Char
>
vsprintf
(
basic_string_view
<
Char
>
format
,
vsprintf
(
const
S
&
format
,
basic_format_args
<
typename
printf_context
<
basic_format_args
<
typename
printf_context
<
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
format
,
args
);
printf
(
buffer
,
to_string_view
(
format
)
,
args
);
return
to_string
(
buffer
);
return
to_string
(
buffer
);
}
}
...
@@ -601,21 +601,21 @@ vsprintf(basic_string_view<Char> format,
...
@@ -601,21 +601,21 @@ vsprintf(basic_string_view<Char> format,
*/
*/
template
<
typename
S
,
typename
...
Args
>
template
<
typename
S
,
typename
...
Args
>
inline
FMT_ENABLE_IF_STRING
(
S
,
std
::
basic_string
<
FMT_CHAR
(
S
)
>
)
inline
FMT_ENABLE_IF_STRING
(
S
,
std
::
basic_string
<
FMT_CHAR
(
S
)
>
)
sprintf
(
const
S
&
format
_str
,
const
Args
&
...
args
)
{
sprintf
(
const
S
&
format
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format
_str
);
internal
::
check_format_string
<
Args
...
>
(
format
);
typedef
internal
::
basic_buffer
<
FMT_CHAR
(
S
)
>
buffer
;
typedef
internal
::
basic_buffer
<
FMT_CHAR
(
S
)
>
buffer
;
typedef
typename
printf_context
<
buffer
>::
type
context
;
typedef
typename
printf_context
<
buffer
>::
type
context
;
format_arg_store
<
context
,
Args
...
>
as
{
args
...
};
format_arg_store
<
context
,
Args
...
>
as
{
args
...
};
return
vsprintf
(
to_string_view
(
format
_str
),
return
vsprintf
(
to_string_view
(
format
),
basic_format_args
<
context
>
(
as
));
basic_format_args
<
context
>
(
as
));
}
}
template
<
typename
Char
>
template
<
typename
S
,
typename
Char
=
FMT_CHAR
(
S
)
>
inline
int
vfprintf
(
std
::
FILE
*
f
,
basic_string_view
<
Char
>
format
,
inline
int
vfprintf
(
std
::
FILE
*
f
,
const
S
&
format
,
basic_format_args
<
typename
printf_context
<
basic_format_args
<
typename
printf_context
<
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
format
,
args
);
printf
(
buffer
,
to_string_view
(
format
)
,
args
);
std
::
size_t
size
=
buffer
.
size
();
std
::
size_t
size
=
buffer
.
size
();
return
std
::
fwrite
(
return
std
::
fwrite
(
buffer
.
data
(),
sizeof
(
Char
),
size
,
f
)
<
size
?
-
1
:
static_cast
<
int
>
(
size
);
buffer
.
data
(),
sizeof
(
Char
),
size
,
f
)
<
size
?
-
1
:
static_cast
<
int
>
(
size
);
...
@@ -632,20 +632,20 @@ inline int vfprintf(std::FILE *f, basic_string_view<Char> format,
...
@@ -632,20 +632,20 @@ inline int vfprintf(std::FILE *f, basic_string_view<Char> format,
*/
*/
template
<
typename
S
,
typename
...
Args
>
template
<
typename
S
,
typename
...
Args
>
inline
FMT_ENABLE_IF_STRING
(
S
,
int
)
inline
FMT_ENABLE_IF_STRING
(
S
,
int
)
fprintf
(
std
::
FILE
*
f
,
const
S
&
format
_str
,
const
Args
&
...
args
)
{
fprintf
(
std
::
FILE
*
f
,
const
S
&
format
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format
_str
);
internal
::
check_format_string
<
Args
...
>
(
format
);
typedef
internal
::
basic_buffer
<
FMT_CHAR
(
S
)
>
buffer
;
typedef
internal
::
basic_buffer
<
FMT_CHAR
(
S
)
>
buffer
;
typedef
typename
printf_context
<
buffer
>::
type
context
;
typedef
typename
printf_context
<
buffer
>::
type
context
;
format_arg_store
<
context
,
Args
...
>
as
{
args
...
};
format_arg_store
<
context
,
Args
...
>
as
{
args
...
};
return
vfprintf
(
f
,
to_string_view
(
format
_str
),
return
vfprintf
(
f
,
to_string_view
(
format
),
basic_format_args
<
context
>
(
as
));
basic_format_args
<
context
>
(
as
));
}
}
template
<
typename
Char
>
template
<
typename
S
,
typename
Char
=
FMT_CHAR
(
S
)
>
inline
int
vprintf
(
basic_string_view
<
Char
>
format
,
inline
int
vprintf
(
const
S
&
format
,
basic_format_args
<
typename
printf_context
<
basic_format_args
<
typename
printf_context
<
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
return
vfprintf
(
stdout
,
format
,
args
);
return
vfprintf
(
stdout
,
to_string_view
(
format
)
,
args
);
}
}
/**
/**
...
@@ -668,13 +668,13 @@ inline FMT_ENABLE_IF_STRING(S, int)
...
@@ -668,13 +668,13 @@ inline FMT_ENABLE_IF_STRING(S, int)
basic_format_args
<
context
>
(
as
));
basic_format_args
<
context
>
(
as
));
}
}
template
<
typename
Char
>
template
<
typename
S
,
typename
Char
=
FMT_CHAR
(
S
)
>
inline
int
vfprintf
(
std
::
basic_ostream
<
Char
>
&
os
,
inline
int
vfprintf
(
std
::
basic_ostream
<
Char
>
&
os
,
basic_string_view
<
Char
>
format_str
,
const
S
&
format
,
basic_format_args
<
typename
printf_context
<
basic_format_args
<
typename
printf_context
<
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
internal
::
basic_buffer
<
Char
>>::
type
>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
format_str
,
args
);
printf
(
buffer
,
to_string_view
(
format
)
,
args
);
internal
::
write
(
os
,
buffer
);
internal
::
write
(
os
,
buffer
);
return
static_cast
<
int
>
(
buffer
.
size
());
return
static_cast
<
int
>
(
buffer
.
size
());
}
}
...
...
test/printf-test.cc
View file @
0a96c032
...
@@ -499,3 +499,13 @@ TEST(PrintfTest, OStream) {
...
@@ -499,3 +499,13 @@ TEST(PrintfTest, OStream) {
EXPECT_EQ
(
"Don't panic!"
,
os
.
str
());
EXPECT_EQ
(
"Don't panic!"
,
os
.
str
());
EXPECT_EQ
(
12
,
ret
);
EXPECT_EQ
(
12
,
ret
);
}
}
TEST
(
PrintfTest
,
VPrintf
)
{
typedef
fmt
::
printf_context
<
fmt
::
internal
::
buffer
>::
type
context
;
fmt
::
format_arg_store
<
context
,
int
>
as
{
42
};
fmt
::
basic_format_args
<
context
>
args
(
as
);
EXPECT_EQ
(
fmt
::
vsprintf
(
"%d"
,
args
),
"42"
);
EXPECT_WRITE
(
stdout
,
fmt
::
vprintf
(
"%d"
,
args
),
"42"
);
EXPECT_WRITE
(
stdout
,
fmt
::
vfprintf
(
stdout
,
"%d"
,
args
),
"42"
);
EXPECT_WRITE
(
stdout
,
fmt
::
vfprintf
(
std
::
cout
,
"%d"
,
args
),
"42"
);
}
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