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
9dbb60c4
Commit
9dbb60c4
authored
Aug 03, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move fmt::fprintf to printf.h
parent
ed301089
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
48 deletions
+47
-48
doc/api.rst
doc/api.rst
+2
-2
fmt/ostream.cc
fmt/ostream.cc
+3
-12
fmt/ostream.h
fmt/ostream.h
+3
-12
fmt/printf.h
fmt/printf.h
+18
-1
test/ostream-test.cc
test/ostream-test.cc
+3
-21
test/printf-test.cc
test/printf-test.cc
+11
-0
test/util.h
test/util.h
+7
-0
No files found.
doc/api.rst
View file @
9dbb60c4
...
...
@@ -81,8 +81,6 @@ formatting of user-defined types that have overloaded ``operator<<``::
.. doxygenfunction:: print(std::ostream&, CStringRef, ArgList)
.. doxygenfunction:: fprintf(std::ostream&, CStringRef, ArgList)
Argument formatters
-------------------
...
...
@@ -140,6 +138,8 @@ argument type doesn't match its format specification.
.. doxygenfunction:: fprintf(std::FILE *, CStringRef, ArgList)
.. doxygenfunction:: fprintf(std::ostream&, CStringRef, ArgList)
.. doxygenfunction:: sprintf(CStringRef, ArgList)
.. doxygenclass:: fmt::PrintfFormatter
...
...
fmt/ostream.cc
View file @
9dbb60c4
...
...
@@ -8,13 +8,11 @@
*/
#include "fmt/ostream.h"
#include "fmt/printf.h"
namespace
fmt
{
namespace
{
// Write the content of w to os.
void
write
(
std
::
ostream
&
os
,
Writer
&
w
)
{
namespace
internal
{
FMT_FUNC
void
write
(
std
::
ostream
&
os
,
Writer
&
w
)
{
const
char
*
data
=
w
.
data
();
typedef
internal
::
MakeUnsigned
<
std
::
streamsize
>::
Type
UnsignedStreamSize
;
UnsignedStreamSize
size
=
w
.
size
();
...
...
@@ -32,13 +30,6 @@ void write(std::ostream &os, Writer &w) {
FMT_FUNC
void
print
(
std
::
ostream
&
os
,
CStringRef
format_str
,
ArgList
args
)
{
MemoryWriter
w
;
w
.
write
(
format_str
,
args
);
write
(
os
,
w
);
}
FMT_FUNC
int
fprintf
(
std
::
ostream
&
os
,
CStringRef
format
,
ArgList
args
)
{
MemoryWriter
w
;
printf
(
w
,
format
,
args
);
write
(
os
,
w
);
return
static_cast
<
int
>
(
w
.
size
());
internal
::
write
(
os
,
w
);
}
}
// namespace fmt
fmt/ostream.h
View file @
9dbb60c4
...
...
@@ -66,6 +66,9 @@ struct ConvertToIntImpl<T, true> {
value
=
sizeof
(
convert
(
get
<
DummyStream
>
()
<<
get
<
T
>
()))
==
sizeof
(
No
)
};
};
// Write the content of w to os.
void
write
(
std
::
ostream
&
os
,
Writer
&
w
);
}
// namespace internal
// Formats a value.
...
...
@@ -94,18 +97,6 @@ void format(BasicFormatter<Char, ArgFormatter> &f,
*/
FMT_API
void
print
(
std
::
ostream
&
os
,
CStringRef
format_str
,
ArgList
args
);
FMT_VARIADIC
(
void
,
print
,
std
::
ostream
&
,
CStringRef
)
/**
\rst
Prints formatted data to the stream *os*.
**Example**::
fprintf(cerr, "Don't %s!", "panic");
\endrst
*/
FMT_API
int
fprintf
(
std
::
ostream
&
os
,
CStringRef
format_str
,
ArgList
args
);
FMT_VARIADIC
(
int
,
fprintf
,
std
::
ostream
&
,
CStringRef
)
}
// namespace fmt
#ifdef FMT_HEADER_ONLY
...
...
fmt/printf.h
View file @
9dbb60c4
...
...
@@ -13,7 +13,7 @@
#include <algorithm> // std::fill_n
#include <limits> // std::numeric_limits
#include "fmt/
format
.h"
#include "fmt/
ostream
.h"
namespace
fmt
{
namespace
internal
{
...
...
@@ -536,6 +536,23 @@ inline int printf(CStringRef format, ArgList args) {
return
fprintf
(
stdout
,
format
,
args
);
}
FMT_VARIADIC
(
int
,
printf
,
CStringRef
)
/**
\rst
Prints formatted data to the stream *os*.
**Example**::
fprintf(cerr, "Don't %s!", "panic");
\endrst
*/
inline
int
fprintf
(
std
::
ostream
&
os
,
CStringRef
format_str
,
ArgList
args
)
{
MemoryWriter
w
;
printf
(
w
,
format_str
,
args
);
internal
::
write
(
os
,
w
);
return
static_cast
<
int
>
(
w
.
size
());
}
FMT_VARIADIC
(
int
,
fprintf
,
std
::
ostream
&
,
CStringRef
)
}
// namespace fmt
#endif // FMT_PRINTF_H_
test/ostream-test.cc
View file @
9dbb60c4
...
...
@@ -25,7 +25,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "fmt/ostream.
cc
"
#include "fmt/ostream.
h
"
#include <sstream>
#include "gmock/gmock.h"
...
...
@@ -35,13 +35,6 @@
using
fmt
::
format
;
using
fmt
::
FormatError
;
template
<
typename
Char
>
std
::
basic_ostream
<
Char
>
&
operator
<<
(
std
::
basic_ostream
<
Char
>
&
os
,
const
BasicTestString
<
Char
>
&
s
)
{
os
<<
s
.
value
();
return
os
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Date
&
d
)
{
os
<<
d
.
year
()
<<
'-'
<<
d
.
month
()
<<
'-'
<<
d
.
day
();
return
os
;
...
...
@@ -128,22 +121,11 @@ TEST(OStreamTest, Print) {
EXPECT_EQ
(
"Don't panic!"
,
os
.
str
());
}
TEST
(
OStreamTest
,
PrintfCustom
)
{
EXPECT_EQ
(
"abc"
,
fmt
::
sprintf
(
"%s"
,
TestString
(
"abc"
)));
}
TEST
(
OStreamTest
,
FPrintf
)
{
std
::
ostringstream
os
;
int
ret
=
fmt
::
fprintf
(
os
,
"Don't %s!"
,
"panic"
);
EXPECT_EQ
(
"Don't panic!"
,
os
.
str
());
EXPECT_EQ
(
12
,
ret
);
}
TEST
(
OStreamTest
,
WriteToOStream
)
{
std
::
ostringstream
os
;
fmt
::
MemoryWriter
w
;
w
<<
"foo"
;
fmt
::
write
(
os
,
w
);
fmt
::
internal
::
write
(
os
,
w
);
EXPECT_EQ
(
"foo"
,
os
.
str
());
}
...
...
@@ -188,5 +170,5 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
data
+=
n
;
size
-=
static_cast
<
std
::
size_t
>
(
n
);
}
while
(
size
!=
0
);
fmt
::
write
(
os
,
w
);
fmt
::
internal
::
write
(
os
,
w
);
}
test/printf-test.cc
View file @
9dbb60c4
...
...
@@ -479,3 +479,14 @@ TEST(PrintfTest, PrintfError) {
TEST
(
PrintfTest
,
WideString
)
{
EXPECT_EQ
(
L"abc"
,
fmt
::
sprintf
(
L"%s"
,
L"abc"
));
}
TEST
(
PrintfTest
,
PrintfCustom
)
{
EXPECT_EQ
(
"abc"
,
fmt
::
sprintf
(
"%s"
,
TestString
(
"abc"
)));
}
TEST
(
PrintfTest
,
OStream
)
{
std
::
ostringstream
os
;
int
ret
=
fmt
::
fprintf
(
os
,
"Don't %s!"
,
"panic"
);
EXPECT_EQ
(
"Don't panic!"
,
os
.
str
());
EXPECT_EQ
(
12
,
ret
);
}
test/util.h
View file @
9dbb60c4
...
...
@@ -87,6 +87,13 @@ const Char BasicTestString<Char>::EMPTY[] = {0};
typedef
BasicTestString
<
char
>
TestString
;
typedef
BasicTestString
<
wchar_t
>
TestWString
;
template
<
typename
Char
>
std
::
basic_ostream
<
Char
>
&
operator
<<
(
std
::
basic_ostream
<
Char
>
&
os
,
const
BasicTestString
<
Char
>
&
s
)
{
os
<<
s
.
value
();
return
os
;
}
class
Date
{
int
year_
,
month_
,
day_
;
public:
...
...
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