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
624c5868
Commit
624c5868
authored
Feb 05, 2017
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify API
parent
7ae8bd70
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
82 additions
and
85 deletions
+82
-85
fmt/format.cc
fmt/format.cc
+3
-3
fmt/format.h
fmt/format.h
+47
-49
fmt/ostream.h
fmt/ostream.h
+3
-3
fmt/posix.h
fmt/posix.h
+1
-1
fmt/printf.h
fmt/printf.h
+10
-10
fmt/time.h
fmt/time.h
+1
-1
test/custom-formatter-test.cc
test/custom-formatter-test.cc
+3
-3
test/format-impl-test.cc
test/format-impl-test.cc
+2
-2
test/format-test.cc
test/format-test.cc
+5
-5
test/ostream-test.cc
test/ostream-test.cc
+3
-4
test/util-test.cc
test/util-test.cc
+4
-4
No files found.
fmt/format.cc
View file @
624c5868
...
...
@@ -465,7 +465,7 @@ template struct internal::BasicData<void>;
template
void
internal
::
FixedBuffer
<
char
>
::
grow
(
std
::
size_t
);
template
void
internal
::
ArgMap
<
format_
context
>
::
init
(
const
format_args
&
args
);
template
void
internal
::
ArgMap
<
context
>
::
init
(
const
format_args
&
args
);
template
void
printf_context
<
char
>
::
format
(
writer
&
writer
);
...
...
@@ -479,11 +479,11 @@ template int internal::CharTraits<char>::format_float(
// Explicit instantiations for wchar_t.
template
class
basic_
format_
context
<
wchar_t
>;
template
class
basic_context
<
wchar_t
>;
template
void
internal
::
FixedBuffer
<
wchar_t
>
::
grow
(
std
::
size_t
);
template
void
internal
::
ArgMap
<
w
format_
context
>
::
init
(
const
wformat_args
&
args
);
template
void
internal
::
ArgMap
<
wcontext
>
::
init
(
const
wformat_args
&
args
);
template
void
printf_context
<
wchar_t
>
::
format
(
wwriter
&
writer
);
...
...
fmt/format.h
View file @
624c5868
This diff is collapsed.
Click to expand it.
fmt/ostream.h
View file @
624c5868
...
...
@@ -84,11 +84,11 @@ BasicStringRef<Char> format_value(
// Formats a value.
template
<
typename
Char
,
typename
T
>
void
format_value
(
basic_writer
<
Char
>
&
w
,
const
T
&
value
,
basic_
format_
context
<
Char
>
&
ctx
)
{
basic_context
<
Char
>
&
ctx
)
{
internal
::
MemoryBuffer
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
buffer
;
auto
str
=
internal
::
format_value
(
buffer
,
value
);
do_format_arg
<
ArgFormatter
<
Char
>
>
(
w
,
internal
::
make_arg
<
basic_
format_
context
<
Char
>
>
(
str
),
ctx
);
w
,
internal
::
make_arg
<
basic_context
<
Char
>
>
(
str
),
ctx
);
}
FMT_API
void
vprint
(
std
::
ostream
&
os
,
CStringRef
format_str
,
format_args
args
);
...
...
@@ -105,7 +105,7 @@ FMT_API void vprint(std::ostream &os, CStringRef format_str, format_args args);
template
<
typename
...
Args
>
inline
void
print
(
std
::
ostream
&
os
,
CStringRef
format_str
,
const
Args
&
...
args
)
{
vprint
(
os
,
format_str
,
make_
format_
args
(
args
...));
vprint
(
os
,
format_str
,
make_args
(
args
...));
}
}
// namespace fmt
...
...
fmt/posix.h
View file @
624c5868
...
...
@@ -172,7 +172,7 @@ public:
template
<
typename
...
Args
>
inline
void
print
(
CStringRef
format_str
,
const
Args
&
...
args
)
{
vprint
(
format_str
,
make_
format_
args
(
args
...));
vprint
(
format_str
,
make_args
(
args
...));
}
};
...
...
fmt/printf.h
View file @
624c5868
...
...
@@ -103,7 +103,7 @@ class ArgConverter {
bool
is_signed
=
type_
==
'd'
||
type_
==
'i'
;
typedef
typename
internal
::
Conditional
<
is_same
<
T
,
void
>::
value
,
U
,
T
>::
type
TargetType
;
typedef
basic_
format_context
<
Char
>
format_
context
;
typedef
basic_
context
<
Char
>
context
;
if
(
sizeof
(
TargetType
)
<=
sizeof
(
int
))
{
// Extra casts are used to silence warnings.
if
(
is_signed
)
{
...
...
@@ -287,8 +287,8 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
/** Formats an argument of a custom (user-defined) type. */
void
operator
()(
internal
::
CustomValue
<
Char
>
c
)
{
const
Char
format_str
[]
=
{
'}'
,
'\0'
};
auto
args
=
basic_args
<
basic_
format_
context
<
Char
>>
();
basic_
format_
context
<
Char
>
ctx
(
format_str
,
args
);
auto
args
=
basic_args
<
basic_context
<
Char
>>
();
basic_context
<
Char
>
ctx
(
format_str
,
args
);
c
.
format
(
this
->
writer
(),
c
.
value
,
&
ctx
);
}
};
...
...
@@ -297,14 +297,14 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
template
<
typename
Char
,
typename
ArgFormatter
=
PrintfArgFormatter
<
Char
>
>
class
printf_context
:
private
internal
::
format_
context_base
<
private
internal
::
context_base
<
Char
,
printf_context
<
Char
,
ArgFormatter
>>
{
public:
/** The character type for the output. */
typedef
Char
char_type
;
private:
typedef
internal
::
format_
context_base
<
Char
,
printf_context
>
Base
;
typedef
internal
::
context_base
<
Char
,
printf_context
>
Base
;
typedef
typename
Base
::
format_arg
format_arg
;
typedef
basic_format_specs
<
Char
>
format_specs
;
...
...
@@ -539,7 +539,7 @@ inline std::string vsprintf(CStringRef format, printf_args args) {
*/
template
<
typename
...
Args
>
inline
std
::
string
sprintf
(
CStringRef
format_str
,
const
Args
&
...
args
)
{
return
vsprintf
(
format_str
,
make_
xformat_
args
<
printf_context
<
char
>>
(
args
...));
return
vsprintf
(
format_str
,
make_args
<
printf_context
<
char
>>
(
args
...));
}
inline
std
::
wstring
vsprintf
(
...
...
@@ -551,7 +551,7 @@ inline std::wstring vsprintf(
template
<
typename
...
Args
>
inline
std
::
wstring
sprintf
(
WCStringRef
format_str
,
const
Args
&
...
args
)
{
auto
vargs
=
make_
xformat_
args
<
printf_context
<
wchar_t
>>
(
args
...);
auto
vargs
=
make_args
<
printf_context
<
wchar_t
>>
(
args
...);
return
vsprintf
(
format_str
,
vargs
);
}
...
...
@@ -568,7 +568,7 @@ FMT_API int vfprintf(std::FILE *f, CStringRef format, printf_args args);
*/
template
<
typename
...
Args
>
inline
int
fprintf
(
std
::
FILE
*
f
,
CStringRef
format_str
,
const
Args
&
...
args
)
{
auto
vargs
=
make_
xformat_
args
<
printf_context
<
char
>>
(
args
...);
auto
vargs
=
make_args
<
printf_context
<
char
>>
(
args
...);
return
vfprintf
(
f
,
format_str
,
vargs
);
}
...
...
@@ -587,7 +587,7 @@ inline int vprintf(CStringRef format, printf_args args) {
*/
template
<
typename
...
Args
>
inline
int
printf
(
CStringRef
format_str
,
const
Args
&
...
args
)
{
return
vprintf
(
format_str
,
make_
xformat_
args
<
printf_context
<
char
>>
(
args
...));
return
vprintf
(
format_str
,
make_args
<
printf_context
<
char
>>
(
args
...));
}
inline
int
vfprintf
(
std
::
ostream
&
os
,
CStringRef
format_str
,
printf_args
args
)
{
...
...
@@ -609,7 +609,7 @@ inline int vfprintf(std::ostream &os, CStringRef format_str, printf_args args) {
template
<
typename
...
Args
>
inline
int
fprintf
(
std
::
ostream
&
os
,
CStringRef
format_str
,
const
Args
&
...
args
)
{
auto
vargs
=
make_
xformat_
args
<
printf_context
<
char
>>
(
args
...);
auto
vargs
=
make_args
<
printf_context
<
char
>>
(
args
...);
return
vfprintf
(
os
,
format_str
,
vargs
);
}
}
// namespace fmt
...
...
fmt/time.h
View file @
624c5868
...
...
@@ -15,7 +15,7 @@
namespace
fmt
{
void
format_value
(
writer
&
w
,
const
std
::
tm
&
tm
,
format_
context
&
ctx
)
{
void
format_value
(
writer
&
w
,
const
std
::
tm
&
tm
,
context
&
ctx
)
{
const
char
*&
s
=
ctx
.
ptr
();
if
(
*
s
==
':'
)
++
s
;
...
...
test/custom-formatter-test.cc
View file @
624c5868
...
...
@@ -16,7 +16,7 @@ using fmt::PrintfArgFormatter;
// rounded to 0.
class
CustomArgFormatter
:
public
fmt
::
ArgFormatter
<
char
>
{
public:
CustomArgFormatter
(
fmt
::
writer
&
w
,
fmt
::
basic_
format_
context
<
char
>
&
ctx
,
CustomArgFormatter
(
fmt
::
writer
&
w
,
fmt
::
basic_context
<
char
>
&
ctx
,
fmt
::
format_specs
&
s
)
:
fmt
::
ArgFormatter
<
char
>
(
w
,
ctx
,
s
)
{}
...
...
@@ -54,7 +54,7 @@ std::string custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template
<
typename
...
Args
>
std
::
string
custom_format
(
const
char
*
format_str
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_
format_
args
(
args
...);
auto
va
=
fmt
::
make_args
(
args
...);
return
custom_vformat
(
format_str
,
va
);
}
...
...
@@ -72,7 +72,7 @@ std::string custom_vsprintf(
template
<
typename
...
Args
>
std
::
string
custom_sprintf
(
const
char
*
format_str
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_
xformat_
args
<
CustomPrintfFormatter
>
(
args
...);
auto
va
=
fmt
::
make_args
<
CustomPrintfFormatter
>
(
args
...);
return
custom_vsprintf
(
format_str
,
va
);
}
...
...
test/format-impl-test.cc
View file @
624c5868
...
...
@@ -57,9 +57,9 @@ struct ValueExtractor {
TEST
(
FormatTest
,
ArgConverter
)
{
using
fmt
::
format_arg
;
fmt
::
LongLong
value
=
std
::
numeric_limits
<
fmt
::
LongLong
>::
max
();
format_arg
arg
=
fmt
::
internal
::
make_arg
<
fmt
::
format_
context
>
(
value
);
format_arg
arg
=
fmt
::
internal
::
make_arg
<
fmt
::
context
>
(
value
);
visit
(
fmt
::
internal
::
ArgConverter
<
fmt
::
LongLong
,
fmt
::
format_
context
>
(
arg
,
'd'
),
arg
);
fmt
::
LongLong
,
fmt
::
context
>
(
arg
,
'd'
),
arg
);
EXPECT_EQ
(
value
,
visit
(
ValueExtractor
<
fmt
::
LongLong
>
(),
arg
));
}
...
...
test/format-test.cc
View file @
624c5868
...
...
@@ -1366,7 +1366,7 @@ TEST(FormatterTest, FormatCStringRef) {
EXPECT_EQ
(
"test"
,
format
(
"{0}"
,
CStringRef
(
"test"
)));
}
void
format_value
(
fmt
::
writer
&
w
,
const
Date
&
d
,
fmt
::
format_
context
&
)
{
void
format_value
(
fmt
::
writer
&
w
,
const
Date
&
d
,
fmt
::
context
&
)
{
w
.
write
(
d
.
year
());
w
.
write
(
'-'
);
w
.
write
(
d
.
month
());
...
...
@@ -1383,7 +1383,7 @@ TEST(FormatterTest, FormatCustom) {
class
Answer
{};
template
<
typename
Char
>
void
format_value
(
basic_writer
<
Char
>
&
w
,
Answer
,
fmt
::
format_
context
&
)
{
void
format_value
(
basic_writer
<
Char
>
&
w
,
Answer
,
fmt
::
context
&
)
{
w
.
write
(
"42"
);
}
...
...
@@ -1575,7 +1575,7 @@ std::string vformat_message(int id, const char *format, fmt::format_args args) {
template
<
typename
...
Args
>
std
::
string
format_message
(
int
id
,
const
char
*
format
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_
format_
args
(
args
...);
auto
va
=
fmt
::
make_args
(
args
...);
return
vformat_message
(
id
,
format
,
va
);
}
...
...
@@ -1643,7 +1643,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
public:
typedef
fmt
::
internal
::
ArgFormatterBase
<
char
>
Base
;
MockArgFormatter
(
fmt
::
writer
&
w
,
fmt
::
format_
context
&
ctx
,
MockArgFormatter
(
fmt
::
writer
&
w
,
fmt
::
context
&
ctx
,
fmt
::
format_specs
&
s
)
:
fmt
::
internal
::
ArgFormatterBase
<
char
>
(
w
,
s
)
{
EXPECT_CALL
(
*
this
,
call
(
42
));
...
...
@@ -1663,7 +1663,7 @@ void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template
<
typename
...
Args
>
void
custom_format
(
const
char
*
format_str
,
const
Args
&
...
args
)
{
auto
va
=
fmt
::
make_
format_
args
(
args
...);
auto
va
=
fmt
::
make_args
(
args
...);
return
custom_vformat
(
format_str
,
va
);
}
...
...
test/ostream-test.cc
View file @
624c5868
...
...
@@ -59,17 +59,16 @@ TEST(OStreamTest, Enum) {
}
struct
TestArgFormatter
:
fmt
::
ArgFormatter
<
char
>
{
TestArgFormatter
(
fmt
::
writer
&
w
,
fmt
::
format_context
&
ctx
,
fmt
::
format_specs
&
s
)
TestArgFormatter
(
fmt
::
writer
&
w
,
fmt
::
context
&
ctx
,
fmt
::
format_specs
&
s
)
:
fmt
::
ArgFormatter
<
char
>
(
w
,
ctx
,
s
)
{}
};
TEST
(
OStreamTest
,
CustomArg
)
{
fmt
::
MemoryWriter
writer
;
fmt
::
format_
context
ctx
(
"}"
,
fmt
::
format_args
());
fmt
::
context
ctx
(
"}"
,
fmt
::
format_args
());
fmt
::
format_specs
spec
;
TestArgFormatter
af
(
writer
,
ctx
,
spec
);
visit
(
af
,
fmt
::
internal
::
make_arg
<
fmt
::
format_
context
>
(
TestEnum
()));
visit
(
af
,
fmt
::
internal
::
make_arg
<
fmt
::
context
>
(
TestEnum
()));
EXPECT_EQ
(
"TestEnum"
,
writer
.
str
());
}
...
...
test/util-test.cc
View file @
624c5868
...
...
@@ -69,7 +69,7 @@ struct Test {};
template
<
typename
Char
>
void
format_value
(
fmt
::
basic_writer
<
Char
>
&
w
,
Test
,
fmt
::
basic_
format_
context
<
Char
>
&
)
{
fmt
::
basic_context
<
Char
>
&
)
{
w
.
write
(
"test"
);
}
...
...
@@ -487,7 +487,7 @@ VISIT_TYPE(float, double);
#define CHECK_ARG_(Char, expected, value) { \
testing::StrictMock<MockVisitor<decltype(expected)>> visitor; \
EXPECT_CALL(visitor, visit(expected)); \
fmt::visit(visitor, make_arg<fmt::basic_
format_
context<Char>>(value)); \
fmt::visit(visitor, make_arg<fmt::basic_context<Char>>(value)); \
}
#define CHECK_ARG(value) { \
...
...
@@ -570,12 +570,12 @@ TEST(UtilTest, CustomArg) {
testing
::
Invoke
([
&
](
fmt
::
internal
::
CustomValue
<
char
>
custom
)
{
EXPECT_EQ
(
&
test
,
custom
.
value
);
fmt
::
MemoryWriter
w
;
fmt
::
format_
context
ctx
(
"}"
,
fmt
::
format_args
());
fmt
::
context
ctx
(
"}"
,
fmt
::
format_args
());
custom
.
format
(
w
,
&
test
,
&
ctx
);
EXPECT_EQ
(
"test"
,
w
.
str
());
return
Visitor
::
Result
();
}));
fmt
::
visit
(
visitor
,
make_arg
<
fmt
::
format_
context
>
(
test
));
fmt
::
visit
(
visitor
,
make_arg
<
fmt
::
context
>
(
test
));
}
TEST
(
ArgVisitorTest
,
VisitInvalidArg
)
{
...
...
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