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
552416bd
Commit
552416bd
authored
Nov 16, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fmt_helper cleanup
parent
b5224130
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
58 deletions
+36
-58
include/spdlog/details/fmt_helper.h
include/spdlog/details/fmt_helper.h
+34
-56
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+2
-2
No files found.
include/spdlog/details/fmt_helper.h
View file @
552416bd
...
...
@@ -4,7 +4,8 @@
#pragma once
#include "chrono"
#include <chrono>
#include <type_traits>
#include "spdlog/fmt/fmt.h"
// Some fmt helpers to efficiently format and pad ints and strings
...
...
@@ -41,88 +42,65 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
dest
.
append
(
i
.
data
(),
i
.
data
()
+
i
.
size
());
}
template
<
size_t
Buffer_Size
>
inline
void
pad2
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
append_uint
(
T
n
,
unsigned
int
width
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99
)
{
append_int
(
n
,
dest
);
return
;
}
if
(
n
>
9
)
// 10-99
{
dest
.
push_back
(
static_cast
<
char
>
(
'0'
+
n
/
10
));
dest
.
push_back
(
static_cast
<
char
>
(
'0'
+
n
%
10
));
return
;
}
if
(
n
>=
0
)
// 0-9
static_assert
(
std
::
is_unsigned
<
T
>::
value
,
"append_uint must get unsigned T"
);
auto
digits
=
fmt
::
internal
::
count_digits
(
n
);
if
(
width
>
digits
)
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
static_cast
<
char
>
(
'0'
+
n
));
return
;
const
char
*
zeroes
=
"0000000000000000000"
;
dest
.
append
(
zeroes
,
zeroes
+
width
-
digits
);
}
// negatives (unlikely, but just in case, let fmt deal with it)
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
append_int
(
n
,
dest
);
}
template
<
size_t
Buffer_Size
>
inline
void
pad
3
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
pad
2
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99
9
)
if
(
n
>
99
)
{
append_int
(
n
,
dest
);
return
;
}
if
(
n
>
99
)
// 100-999
{
dest
.
push_back
(
static_cast
<
char
>
(
'0'
+
n
/
100
));
pad2
(
n
%
100
,
dest
);
return
;
}
if
(
n
>
9
)
// 10-99
else
if
(
n
>
9
)
// 10-99
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
static_cast
<
char
>
(
'0'
+
n
/
10
));
dest
.
push_back
(
static_cast
<
char
>
(
'0'
+
n
%
10
));
return
;
}
if
(
n
>=
0
)
else
if
(
n
>=
0
)
// 0-9
{
dest
.
push_back
(
'0'
);
dest
.
push_back
(
'0'
);
dest
.
push_back
(
static_cast
<
char
>
(
'0'
+
n
));
return
;
}
// negatives (unlikely, but just in case let fmt deal with it)
fmt
::
format_to
(
dest
,
"{:03}"
,
n
);
else
// negatives (unlikely, but just in case, let fmt deal with it)
{
fmt
::
format_to
(
dest
,
"{:02}"
,
n
);
}
}
template
<
size_t
Buffer_Size
>
inline
void
pad
6
(
size_t
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
pad
3
(
T
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99999
)
{
append_int
(
n
,
dest
);
return
;
}
pad3
(
static_cast
<
int
>
(
n
/
1000
),
dest
);
pad3
(
static_cast
<
int
>
(
n
%
1000
),
dest
);
append_uint
(
n
,
3
,
dest
);
}
template
<
size_t
Buffer_Size
>
inline
void
pad
9
(
size_t
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
pad
6
(
T
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
if
(
n
>
99999999
)
{
append_int
(
n
,
dest
);
return
;
}
pad6
(
static_cast
<
int
>
(
n
/
1000
),
dest
);
pad3
(
static_cast
<
int
>
(
n
%
1000
)
,
dest
);
append_uint
(
n
,
6
,
dest
);
}
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
pad9
(
T
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
{
append_uint
(
n
,
9
,
dest
);
}
// return fraction of a second of the given time_point.
// e.g.
// fraction<std::milliseconds>(tp) -> will return the millis part of the second
...
...
include/spdlog/details/pattern_formatter.h
View file @
552416bd
...
...
@@ -452,7 +452,7 @@ public:
scoped_pad
p
(
field_size
,
padinfo_
,
dest
);
auto
millis
=
fmt_helper
::
time_fraction
<
std
::
chrono
::
milliseconds
>
(
msg
.
time
);
fmt_helper
::
pad3
(
static_cast
<
in
t
>
(
millis
.
count
()),
dest
);
fmt_helper
::
pad3
(
static_cast
<
uint32_
t
>
(
millis
.
count
()),
dest
);
}
};
...
...
@@ -818,7 +818,7 @@ public:
fmt_helper
::
append_buf
(
cached_datetime_
,
dest
);
auto
millis
=
fmt_helper
::
time_fraction
<
milliseconds
>
(
msg
.
time
);
fmt_helper
::
pad3
(
static_cast
<
in
t
>
(
millis
.
count
()),
dest
);
fmt_helper
::
pad3
(
static_cast
<
uint32_
t
>
(
millis
.
count
()),
dest
);
dest
.
push_back
(
']'
);
dest
.
push_back
(
' '
);
...
...
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