Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
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
spdlog
Commits
77acf29c
Commit
77acf29c
authored
Aug 07, 2015
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated to latest cppformat lib
parent
cadd181d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
63 deletions
+74
-63
include/spdlog/details/format.cc
include/spdlog/details/format.cc
+26
-32
include/spdlog/details/format.h
include/spdlog/details/format.h
+48
-31
No files found.
include/spdlog/details/format.cc
View file @
77acf29c
...
...
@@ -207,8 +207,8 @@ int safe_strerror(
}
public:
StrError
(
int
err
or_code
,
char
*&
buffer
,
std
::
size_t
buffer
_size
)
:
error_code_
(
err
or_code
),
buffer_
(
buffer
),
buffer_size_
(
buffer
_size
)
{}
StrError
(
int
err
_code
,
char
*&
buf
,
std
::
size_t
buf
_size
)
:
error_code_
(
err
_code
),
buffer_
(
buf
),
buffer_size_
(
buf
_size
)
{}
int
run
()
{
strerror_r
(
0
,
0
,
""
);
// Suppress a warning about unused strerror_r.
...
...
@@ -521,25 +521,25 @@ public:
:
BasicArgFormatter
<
PrintfArgFormatter
<
Char
>
,
Char
>
(
w
,
s
)
{}
void
visit_char
(
int
value
)
{
const
FormatSpec
&
spec
=
this
->
spec
();
BasicWriter
<
Char
>
&
w
riter
=
this
->
writer
();
if
(
spec
.
type_
&&
spec
.
type_
!=
'c'
)
w
riter
.
write_int
(
value
,
spec
);
const
FormatSpec
&
fmt_
spec
=
this
->
spec
();
BasicWriter
<
Char
>
&
w
=
this
->
writer
();
if
(
fmt_spec
.
type_
&&
fmt_
spec
.
type_
!=
'c'
)
w
.
write_int
(
value
,
fmt_
spec
);
typedef
typename
BasicWriter
<
Char
>::
CharPtr
CharPtr
;
CharPtr
out
=
CharPtr
();
if
(
spec
.
width_
>
1
)
{
if
(
fmt_
spec
.
width_
>
1
)
{
Char
fill
=
' '
;
out
=
w
riter
.
grow_buffer
(
spec
.
width_
);
if
(
spec
.
align_
!=
ALIGN_LEFT
)
{
std
::
fill_n
(
out
,
spec
.
width_
-
1
,
fill
);
out
+=
spec
.
width_
-
1
;
out
=
w
.
grow_buffer
(
fmt_
spec
.
width_
);
if
(
fmt_
spec
.
align_
!=
ALIGN_LEFT
)
{
std
::
fill_n
(
out
,
fmt_
spec
.
width_
-
1
,
fill
);
out
+=
fmt_
spec
.
width_
-
1
;
}
else
{
std
::
fill_n
(
out
+
1
,
spec
.
width_
-
1
,
fill
);
std
::
fill_n
(
out
+
1
,
fmt_
spec
.
width_
-
1
,
fill
);
}
}
else
{
out
=
w
riter
.
grow_buffer
(
1
);
out
=
w
.
grow_buffer
(
1
);
}
*
out
=
static_cast
<
Char
>
(
value
);
}
...
...
@@ -959,10 +959,8 @@ unsigned fmt::internal::PrintfFormatter<Char>::parse_header(
template
<
typename
Char
>
void
fmt
::
internal
::
PrintfFormatter
<
Char
>::
format
(
BasicWriter
<
Char
>
&
writer
,
BasicCStringRef
<
Char
>
format_str
,
const
ArgList
&
args
)
{
BasicWriter
<
Char
>
&
writer
,
BasicCStringRef
<
Char
>
format_str
)
{
const
Char
*
start
=
format_str
.
c_str
();
set_args
(
args
);
const
Char
*
s
=
start
;
while
(
*
s
)
{
Char
c
=
*
s
++
;
...
...
@@ -1227,7 +1225,6 @@ const Char *fmt::BasicFormatter<Char>::format(
if
(
*
s
++
!=
'}'
)
FMT_THROW
(
FormatError
(
"missing '}' in format string"
));
start_
=
s
;
// Format argument.
internal
::
ArgFormatter
<
Char
>
(
*
this
,
spec
,
s
-
1
).
visit
(
arg
);
...
...
@@ -1235,25 +1232,24 @@ const Char *fmt::BasicFormatter<Char>::format(
}
template
<
typename
Char
>
void
fmt
::
BasicFormatter
<
Char
>::
format
(
BasicCStringRef
<
Char
>
format_str
,
const
ArgList
&
args
)
{
const
Char
*
s
=
start_
=
format_str
.
c_str
();
set_args
(
args
);
void
fmt
::
BasicFormatter
<
Char
>::
format
(
BasicCStringRef
<
Char
>
format_str
)
{
const
Char
*
s
=
format_str
.
c_str
();
const
Char
*
start
=
s
;
while
(
*
s
)
{
Char
c
=
*
s
++
;
if
(
c
!=
'{'
&&
c
!=
'}'
)
continue
;
if
(
*
s
==
c
)
{
write
(
writer_
,
start
_
,
s
);
start
_
=
++
s
;
write
(
writer_
,
start
,
s
);
start
=
++
s
;
continue
;
}
if
(
c
==
'}'
)
FMT_THROW
(
FormatError
(
"unmatched '}' in format string"
));
write
(
writer_
,
start
_
,
s
-
1
);
write
(
writer_
,
start
,
s
-
1
);
Arg
arg
=
is_name_start
(
*
s
)
?
parse_arg_name
(
s
)
:
parse_arg_index
(
s
);
s
=
format
(
s
,
arg
);
s
tart
=
s
=
format
(
s
,
arg
);
}
write
(
writer_
,
start
_
,
s
);
write
(
writer_
,
start
,
s
);
}
FMT_FUNC
void
fmt
::
report_system_error
(
...
...
@@ -1310,11 +1306,10 @@ template void fmt::internal::FixedBuffer<char>::grow(std::size_t);
template
const
char
*
fmt
::
BasicFormatter
<
char
>
::
format
(
const
char
*&
format_str
,
const
fmt
::
internal
::
Arg
&
arg
);
template
void
fmt
::
BasicFormatter
<
char
>
::
format
(
CStringRef
format
,
const
ArgList
&
args
);
template
void
fmt
::
BasicFormatter
<
char
>
::
format
(
CStringRef
format
);
template
void
fmt
::
internal
::
PrintfFormatter
<
char
>
::
format
(
BasicWriter
<
char
>
&
writer
,
CStringRef
format
,
const
ArgList
&
args
);
BasicWriter
<
char
>
&
writer
,
CStringRef
format
);
template
int
fmt
::
internal
::
CharTraits
<
char
>
::
format_float
(
char
*
buffer
,
std
::
size_t
size
,
const
char
*
format
,
...
...
@@ -1332,11 +1327,10 @@ template const wchar_t *fmt::BasicFormatter<wchar_t>::format(
const
wchar_t
*&
format_str
,
const
fmt
::
internal
::
Arg
&
arg
);
template
void
fmt
::
BasicFormatter
<
wchar_t
>
::
format
(
BasicCStringRef
<
wchar_t
>
format
,
const
ArgList
&
args
);
BasicCStringRef
<
wchar_t
>
format
);
template
void
fmt
::
internal
::
PrintfFormatter
<
wchar_t
>
::
format
(
BasicWriter
<
wchar_t
>
&
writer
,
WCStringRef
format
,
const
ArgList
&
args
);
BasicWriter
<
wchar_t
>
&
writer
,
WCStringRef
format
);
template
int
fmt
::
internal
::
CharTraits
<
wchar_t
>
::
format_float
(
wchar_t
*
buffer
,
std
::
size_t
size
,
const
wchar_t
*
format
,
...
...
include/spdlog/details/format.h
View file @
77acf29c
...
...
@@ -27,7 +27,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef FMT_FORMAT_H_
#define FMT_FORMAT_H_
#define FMT_HEADER_ONLY
#include <stdint.h>
...
...
@@ -763,24 +762,23 @@ inline unsigned count_digits(uint32_t n) {
// Formats a decimal unsigned integer value writing into buffer.
template
<
typename
UInt
,
typename
Char
>
inline
void
format_decimal
(
Char
*
buffer
,
UInt
value
,
unsigned
num_digits
)
{
--
num_digits
;
buffer
+=
num_digits
;
while
(
value
>=
100
)
{
// Integer division is slow so do it for a group of two digits instead
// of for every digit. The idea comes from the talk by Alexandrescu
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned
index
=
(
value
%
100
)
*
2
;
value
/=
100
;
buffer
[
num_digits
]
=
Data
::
DIGITS
[
index
+
1
];
buffer
[
num_digits
-
1
]
=
Data
::
DIGITS
[
index
];
num_digits
-=
2
;
*--
buffer
=
Data
::
DIGITS
[
index
+
1
];
*--
buffer
=
Data
::
DIGITS
[
index
];
}
if
(
value
<
10
)
{
*
buffer
=
static_cast
<
char
>
(
'0'
+
value
);
*
--
buffer
=
static_cast
<
char
>
(
'0'
+
value
);
return
;
}
unsigned
index
=
static_cast
<
unsigned
>
(
value
*
2
);
buffer
[
1
]
=
Data
::
DIGITS
[
index
+
1
];
buffer
[
0
]
=
Data
::
DIGITS
[
index
];
*--
buffer
=
Data
::
DIGITS
[
index
+
1
];
*--
buffer
=
Data
::
DIGITS
[
index
];
}
#ifndef _WIN32
...
...
@@ -924,11 +922,11 @@ private:
static
const
T
&
get
();
static
yes
&
c
heck
(
fmt
::
ULongLong
);
static
no
&
c
heck
(...);
static
yes
&
c
onvert
(
fmt
::
ULongLong
);
static
no
&
c
onvert
(...);
public:
enum
{
value
=
(
sizeof
(
c
heck
(
get
()))
==
sizeof
(
yes
))
};
enum
{
value
=
(
sizeof
(
c
onvert
(
get
()))
==
sizeof
(
yes
))
};
};
#define FMT_CONVERTIBLE_TO_INT(Type) \
...
...
@@ -1127,8 +1125,8 @@ struct NamedArg : Arg {
BasicStringRef
<
Char
>
name
;
template
<
typename
T
>
NamedArg
(
BasicStringRef
<
Char
>
name
,
const
T
&
value
)
:
name
(
name
),
Arg
(
MakeValue
<
Char
>
(
value
))
{
NamedArg
(
BasicStringRef
<
Char
>
arg
name
,
const
T
&
value
)
:
name
(
arg
name
),
Arg
(
MakeValue
<
Char
>
(
value
))
{
type
=
static_cast
<
internal
::
Arg
::
Type
>
(
MakeValue
<
Char
>::
type
(
value
));
}
};
...
...
@@ -1363,7 +1361,7 @@ protected:
return
args_
;
}
void
set_args
(
const
ArgList
&
args
)
{
explicit
FormatterBase
(
const
ArgList
&
args
)
{
args_
=
args
;
next_arg_index_
=
0
;
}
...
...
@@ -1399,8 +1397,8 @@ private:
unsigned
parse_header
(
const
Char
*&
s
,
FormatSpec
&
spec
);
public:
void
format
(
BasicWriter
<
Char
>
&
writer
,
BasicCStringRef
<
Char
>
format_str
,
const
ArgList
&
args
);
explicit
PrintfFormatter
(
const
ArgList
&
args
)
:
FormatterBase
(
args
)
{}
void
format
(
BasicWriter
<
Char
>
&
writer
,
BasicCStringRef
<
Char
>
format_str
);
};
}
// namespace internal
...
...
@@ -1409,7 +1407,6 @@ template <typename Char>
class
BasicFormatter
:
private
internal
::
FormatterBase
{
private:
BasicWriter
<
Char
>
&
writer_
;
const
Char
*
start_
;
internal
::
ArgMap
<
Char
>
map_
;
FMT_DISALLOW_COPY_AND_ASSIGN
(
BasicFormatter
);
...
...
@@ -1427,13 +1424,14 @@ private:
internal
::
Arg
parse_arg_name
(
const
Char
*&
s
);
public:
explicit
BasicFormatter
(
BasicWriter
<
Char
>
&
w
)
:
writer_
(
w
)
{}
BasicFormatter
(
const
ArgList
&
args
,
BasicWriter
<
Char
>
&
w
)
:
FormatterBase
(
args
),
writer_
(
w
)
{}
BasicWriter
<
Char
>
&
writer
()
{
return
writer_
;
}
void
format
(
BasicCStringRef
<
Char
>
format_str
,
const
ArgList
&
args
);
void
format
(
BasicCStringRef
<
Char
>
format_str
);
const
Char
*
format
(
const
Char
*&
format_str
,
const
internal
::
Arg
&
arg
);
};
...
...
@@ -1996,6 +1994,28 @@ private:
return
internal
::
make_ptr
(
&
buffer_
[
size
],
n
);
}
// Writes an unsigned decimal integer.
template
<
typename
UInt
>
Char
*
write_unsigned_decimal
(
UInt
value
,
unsigned
prefix_size
=
0
)
{
unsigned
num_digits
=
internal
::
count_digits
(
value
);
Char
*
ptr
=
get
(
grow_buffer
(
prefix_size
+
num_digits
));
internal
::
format_decimal
(
ptr
+
prefix_size
,
value
,
num_digits
);
return
ptr
;
}
// Writes a decimal integer.
template
<
typename
Int
>
void
write_decimal
(
Int
value
)
{
typename
internal
::
IntTraits
<
Int
>::
MainType
abs_value
=
value
;
if
(
internal
::
is_negative
(
value
))
{
abs_value
=
0
-
abs_value
;
*
write_unsigned_decimal
(
abs_value
,
1
)
=
'-'
;
}
else
{
write_unsigned_decimal
(
abs_value
,
0
);
}
}
// Prepare a buffer for integer formatting.
CharPtr
prepare_int_buffer
(
unsigned
num_digits
,
const
EmptySpec
&
,
const
char
*
prefix
,
unsigned
prefix_size
)
{
...
...
@@ -2123,24 +2143,27 @@ public:
\endrst
*/
void
write
(
BasicCStringRef
<
Char
>
format
,
ArgList
args
)
{
BasicFormatter
<
Char
>
(
*
this
).
format
(
format
,
args
);
BasicFormatter
<
Char
>
(
args
,
*
this
).
format
(
format
);
}
FMT_VARIADIC_VOID
(
write
,
BasicCStringRef
<
Char
>
)
BasicWriter
&
operator
<<
(
int
value
)
{
return
*
this
<<
IntFormatSpec
<
int
>
(
value
);
write_decimal
(
value
);
return
*
this
;
}
BasicWriter
&
operator
<<
(
unsigned
value
)
{
return
*
this
<<
IntFormatSpec
<
unsigned
>
(
value
);
}
BasicWriter
&
operator
<<
(
long
value
)
{
return
*
this
<<
IntFormatSpec
<
long
>
(
value
);
write_decimal
(
value
);
return
*
this
;
}
BasicWriter
&
operator
<<
(
unsigned
long
value
)
{
return
*
this
<<
IntFormatSpec
<
unsigned
long
>
(
value
);
}
BasicWriter
&
operator
<<
(
LongLong
value
)
{
return
*
this
<<
IntFormatSpec
<
LongLong
>
(
value
);
write_decimal
(
value
);
return
*
this
;
}
/**
...
...
@@ -2638,12 +2661,6 @@ public:
typedef
BasicMemoryWriter
<
char
>
MemoryWriter
;
typedef
BasicMemoryWriter
<
wchar_t
>
WMemoryWriter
;
#if defined(WIN32) && defined(SPDLOG_USE_WCHAR)
#define TMemoryWriter WMemoryWriter
#else
#define TMemoryWriter MemoryWriter
#endif
/**
\rst
This class template provides operations for formatting and writing data
...
...
@@ -2823,7 +2840,7 @@ void print(std::ostream &os, CStringRef format_str, ArgList args);
template
<
typename
Char
>
void
printf
(
BasicWriter
<
Char
>
&
w
,
BasicCStringRef
<
Char
>
format
,
ArgList
args
)
{
internal
::
PrintfFormatter
<
Char
>
(
).
format
(
w
,
format
,
args
);
internal
::
PrintfFormatter
<
Char
>
(
args
).
format
(
w
,
format
);
}
/**
...
...
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