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
7698bb0a
Commit
7698bb0a
authored
Apr 15, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bump fmt version to 6.2.0
parent
c89a5148
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1148 additions
and
1034 deletions
+1148
-1034
include/spdlog/fmt/bundled/chrono.h
include/spdlog/fmt/bundled/chrono.h
+41
-28
include/spdlog/fmt/bundled/color.h
include/spdlog/fmt/bundled/color.h
+5
-7
include/spdlog/fmt/bundled/compile.h
include/spdlog/fmt/bundled/compile.h
+17
-7
include/spdlog/fmt/bundled/core.h
include/spdlog/fmt/bundled/core.h
+378
-108
include/spdlog/fmt/bundled/format-inl.h
include/spdlog/fmt/bundled/format-inl.h
+217
-210
include/spdlog/fmt/bundled/format.h
include/spdlog/fmt/bundled/format.h
+334
-227
include/spdlog/fmt/bundled/locale.h
include/spdlog/fmt/bundled/locale.h
+10
-9
include/spdlog/fmt/bundled/ostream.h
include/spdlog/fmt/bundled/ostream.h
+4
-2
include/spdlog/fmt/bundled/posix.h
include/spdlog/fmt/bundled/posix.h
+2
-321
include/spdlog/fmt/bundled/printf.h
include/spdlog/fmt/bundled/printf.h
+29
-19
include/spdlog/fmt/bundled/ranges.h
include/spdlog/fmt/bundled/ranges.h
+26
-4
src/fmt.cpp
src/fmt.cpp
+85
-92
No files found.
include/spdlog/fmt/bundled/chrono.h
View file @
7698bb0a
...
...
@@ -8,14 +8,14 @@
#ifndef FMT_CHRONO_H_
#define FMT_CHRONO_H_
#include "format.h"
#include "locale.h"
#include <chrono>
#include <ctime>
#include <locale>
#include <sstream>
#include "format.h"
#include "locale.h"
FMT_BEGIN_NAMESPACE
// Enable safe chrono durations, unless explicitly disabled.
...
...
@@ -495,12 +495,12 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
handler
.
on_text
(
ptr
-
1
,
ptr
);
break
;
case
'n'
:
{
const
char
newline
[]
=
"
\n
"
;
const
Char
newline
[]
=
{
'\n'
}
;
handler
.
on_text
(
newline
,
newline
+
1
);
break
;
}
case
't'
:
{
const
char
tab
[]
=
"
\t
"
;
const
Char
tab
[]
=
{
'\t'
}
;
handler
.
on_text
(
tab
,
tab
+
1
);
break
;
}
...
...
@@ -759,18 +759,30 @@ inline std::chrono::duration<Rep, std::milli> get_milliseconds(
return
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
(
static_cast
<
Rep
>
(
ms
));
}
template
<
typename
Rep
,
typename
OutputIt
>
OutputIt
format_chrono_duration_value
(
OutputIt
out
,
Rep
val
,
int
precision
)
{
if
(
precision
>=
0
)
return
format_to
(
out
,
"{:.{}f}"
,
val
,
precision
);
return
format_to
(
out
,
std
::
is_floating_point
<
Rep
>::
value
?
"{:g}"
:
"{}"
,
template
<
typename
Char
,
typename
Rep
,
typename
OutputIt
>
OutputIt
format_duration_value
(
OutputIt
out
,
Rep
val
,
int
precision
)
{
const
Char
pr_f
[]
=
{
'{'
,
':'
,
'.'
,
'{'
,
'}'
,
'f'
,
'}'
,
0
};
if
(
precision
>=
0
)
return
format_to
(
out
,
pr_f
,
val
,
precision
);
const
Char
fp_f
[]
=
{
'{'
,
':'
,
'g'
,
'}'
,
0
};
const
Char
format
[]
=
{
'{'
,
'}'
,
0
};
return
format_to
(
out
,
std
::
is_floating_point
<
Rep
>::
value
?
fp_f
:
format
,
val
);
}
template
<
typename
Period
,
typename
OutputIt
>
static
OutputIt
format_chrono_duration_unit
(
OutputIt
out
)
{
if
(
const
char
*
unit
=
get_units
<
Period
>
())
return
format_to
(
out
,
"{}"
,
unit
);
if
(
Period
::
den
==
1
)
return
format_to
(
out
,
"[{}]s"
,
Period
::
num
);
return
format_to
(
out
,
"[{}/{}]s"
,
Period
::
num
,
Period
::
den
);
template
<
typename
Char
,
typename
Period
,
typename
OutputIt
>
OutputIt
format_duration_unit
(
OutputIt
out
)
{
if
(
const
char
*
unit
=
get_units
<
Period
>
())
{
string_view
s
(
unit
);
if
(
const_check
(
std
::
is_same
<
Char
,
wchar_t
>
()))
{
utf8_to_utf16
u
(
s
);
return
std
::
copy
(
u
.
c_str
(),
u
.
c_str
()
+
u
.
size
(),
out
);
}
return
std
::
copy
(
s
.
begin
(),
s
.
end
(),
out
);
}
const
Char
num_f
[]
=
{
'['
,
'{'
,
'}'
,
']'
,
's'
,
0
};
if
(
Period
::
den
==
1
)
return
format_to
(
out
,
num_f
,
Period
::
num
);
const
Char
num_def_f
[]
=
{
'['
,
'{'
,
'}'
,
'/'
,
'{'
,
'}'
,
']'
,
's'
,
0
};
return
format_to
(
out
,
num_def_f
,
Period
::
num
,
Period
::
den
);
}
template
<
typename
FormatContext
,
typename
OutputIt
,
typename
Rep
,
...
...
@@ -871,13 +883,13 @@ struct chrono_formatter {
void
write_pinf
()
{
std
::
copy_n
(
"inf"
,
3
,
out
);
}
void
write_ninf
()
{
std
::
copy_n
(
"-inf"
,
4
,
out
);
}
void
format_localized
(
const
tm
&
time
,
c
onst
char
*
format
)
{
void
format_localized
(
const
tm
&
time
,
c
har
format
,
char
modifier
=
0
)
{
if
(
isnan
(
val
))
return
write_nan
();
auto
locale
=
context
.
locale
().
template
get
<
std
::
locale
>();
auto
&
facet
=
std
::
use_facet
<
std
::
time_put
<
char_type
>>
(
locale
);
std
::
basic_ostringstream
<
char_type
>
os
;
os
.
imbue
(
locale
);
facet
.
put
(
os
,
os
,
' '
,
&
time
,
format
,
format
+
std
::
strlen
(
format
)
);
facet
.
put
(
os
,
os
,
' '
,
&
time
,
format
,
modifier
);
auto
str
=
os
.
str
();
std
::
copy
(
str
.
begin
(),
str
.
end
(),
out
);
}
...
...
@@ -907,7 +919,7 @@ struct chrono_formatter {
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour
(),
2
);
auto
time
=
tm
();
time
.
tm_hour
=
to_nonnegative_int
(
hour
(),
24
);
format_localized
(
time
,
"%OH"
);
format_localized
(
time
,
'H'
,
'O'
);
}
void
on_12_hour
(
numeric_system
ns
)
{
...
...
@@ -916,7 +928,7 @@ struct chrono_formatter {
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour12
(),
2
);
auto
time
=
tm
();
time
.
tm_hour
=
to_nonnegative_int
(
hour12
(),
12
);
format_localized
(
time
,
"%OI"
);
format_localized
(
time
,
'I'
,
'O'
);
}
void
on_minute
(
numeric_system
ns
)
{
...
...
@@ -925,7 +937,7 @@ struct chrono_formatter {
if
(
ns
==
numeric_system
::
standard
)
return
write
(
minute
(),
2
);
auto
time
=
tm
();
time
.
tm_min
=
to_nonnegative_int
(
minute
(),
60
);
format_localized
(
time
,
"%OM"
);
format_localized
(
time
,
'M'
,
'O'
);
}
void
on_second
(
numeric_system
ns
)
{
...
...
@@ -950,13 +962,12 @@ struct chrono_formatter {
}
auto
time
=
tm
();
time
.
tm_sec
=
to_nonnegative_int
(
second
(),
60
);
format_localized
(
time
,
"%OS"
);
format_localized
(
time
,
'S'
,
'O'
);
}
void
on_12_hour_time
()
{
if
(
handle_nan_inf
())
return
;
format_localized
(
time
(),
"%r"
);
format_localized
(
time
(),
'r'
);
}
void
on_24_hour_time
()
{
...
...
@@ -980,16 +991,18 @@ struct chrono_formatter {
void
on_am_pm
()
{
if
(
handle_nan_inf
())
return
;
format_localized
(
time
(),
"%p"
);
format_localized
(
time
(),
'p'
);
}
void
on_duration_value
()
{
if
(
handle_nan_inf
())
return
;
write_sign
();
out
=
format_
chrono_duration_value
(
out
,
val
,
precision
);
out
=
format_
duration_value
<
char_type
>
(
out
,
val
,
precision
);
}
void
on_duration_unit
()
{
out
=
format_chrono_duration_unit
<
Period
>
(
out
);
}
void
on_duration_unit
()
{
out
=
format_duration_unit
<
char_type
,
Period
>
(
out
);
}
};
}
// namespace internal
...
...
@@ -1024,7 +1037,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
}
void
on_error
(
const
char
*
msg
)
{
FMT_THROW
(
format_error
(
msg
));
}
void
on_fill
(
Char
fill
)
{
f
.
specs
.
fill
[
0
]
=
fill
;
}
void
on_fill
(
basic_string_view
<
Char
>
fill
)
{
f
.
specs
.
fill
=
fill
;
}
void
on_align
(
align_t
align
)
{
f
.
specs
.
align
=
align
;
}
void
on_width
(
int
width
)
{
f
.
specs
.
width
=
width
;
}
void
on_precision
(
int
_precision
)
{
f
.
precision
=
_precision
;
}
...
...
@@ -1088,8 +1101,8 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
internal
::
handle_dynamic_spec
<
internal
::
precision_checker
>
(
precision
,
precision_ref
,
ctx
);
if
(
begin
==
end
||
*
begin
==
'}'
)
{
out
=
internal
::
format_
chrono_duration_value
(
out
,
d
.
count
(),
precision
);
internal
::
format_
chrono_duration_unit
<
Period
>
(
out
);
out
=
internal
::
format_
duration_value
<
Char
>
(
out
,
d
.
count
(),
precision
);
internal
::
format_
duration_unit
<
Char
,
Period
>
(
out
);
}
else
{
internal
::
chrono_formatter
<
FormatContext
,
decltype
(
out
),
Rep
,
Period
>
f
(
ctx
,
out
,
d
);
...
...
include/spdlog/fmt/bundled/color.h
View file @
7698bb0a
...
...
@@ -412,7 +412,7 @@ template <typename Char> struct ansi_color_escape {
FMT_CONSTEXPR
const
Char
*
begin
()
const
FMT_NOEXCEPT
{
return
buffer
;
}
FMT_CONSTEXPR
const
Char
*
end
()
const
FMT_NOEXCEPT
{
return
buffer
+
std
::
strlen
(
buffer
);
return
buffer
+
std
::
char_traits
<
Char
>::
length
(
buffer
);
}
private:
...
...
@@ -491,10 +491,8 @@ void vformat_to(basic_memory_buffer<Char>& buf, const text_style& ts,
internal
::
make_background_color
<
Char
>
(
ts
.
get_background
());
buf
.
append
(
background
.
begin
(),
background
.
end
());
}
vformat_to
(
buf
,
format_str
,
args
);
if
(
has_style
)
{
internal
::
reset_color
<
Char
>
(
buf
);
}
internal
::
vformat_to
(
buf
,
format_str
,
args
);
if
(
has_style
)
internal
::
reset_color
<
Char
>
(
buf
);
}
}
// namespace internal
...
...
@@ -540,7 +538,7 @@ void print(const text_style& ts, const S& format_str, const Args&... args) {
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
std
::
basic_string
<
Char
>
vformat
(
const
text_style
&
ts
,
const
S
&
format_str
,
basic_format_args
<
buffer_context
<
Char
>>
args
)
{
basic_format_args
<
buffer_context
<
type_identity_t
<
Char
>
>>
args
)
{
basic_memory_buffer
<
Char
>
buf
;
internal
::
vformat_to
(
buf
,
ts
,
to_string_view
(
format_str
),
args
);
return
fmt
::
to_string
(
buf
);
...
...
@@ -562,7 +560,7 @@ template <typename S, typename... Args, typename Char = char_t<S>>
inline
std
::
basic_string
<
Char
>
format
(
const
text_style
&
ts
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
return
vformat
(
ts
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)}
);
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)
);
}
FMT_END_NAMESPACE
...
...
include/spdlog/fmt/bundled/compile.h
View file @
7698bb0a
...
...
@@ -9,6 +9,7 @@
#define FMT_COMPILE_H_
#include <vector>
#include "format.h"
FMT_BEGIN_NAMESPACE
...
...
@@ -350,6 +351,8 @@ template <int N, typename... Args> struct get_type_impl<N, type_list<Args...>> {
template
<
int
N
,
typename
T
>
using
get_type
=
typename
get_type_impl
<
N
,
T
>::
type
;
template
<
typename
T
>
struct
is_compiled_format
:
std
::
false_type
{};
template
<
typename
Char
>
struct
text
{
basic_string_view
<
Char
>
data
;
using
char_type
=
Char
;
...
...
@@ -361,6 +364,9 @@ template <typename Char> struct text {
}
};
template
<
typename
Char
>
struct
is_compiled_format
<
text
<
Char
>>
:
std
::
true_type
{};
template
<
typename
Char
>
constexpr
text
<
Char
>
make_text
(
basic_string_view
<
Char
>
s
,
size_t
pos
,
size_t
size
)
{
...
...
@@ -406,6 +412,9 @@ template <typename Char, typename T, int N> struct field {
}
};
template
<
typename
Char
,
typename
T
,
int
N
>
struct
is_compiled_format
<
field
<
Char
,
T
,
N
>>
:
std
::
true_type
{};
template
<
typename
L
,
typename
R
>
struct
concat
{
L
lhs
;
R
rhs
;
...
...
@@ -418,6 +427,9 @@ template <typename L, typename R> struct concat {
}
};
template
<
typename
L
,
typename
R
>
struct
is_compiled_format
<
concat
<
L
,
R
>>
:
std
::
true_type
{};
template
<
typename
L
,
typename
R
>
constexpr
concat
<
L
,
R
>
make_concat
(
L
lhs
,
R
rhs
)
{
return
{
lhs
,
rhs
};
...
...
@@ -508,8 +520,7 @@ constexpr auto compile(S format_str) {
template
<
typename
CompiledFormat
,
typename
...
Args
,
typename
Char
=
typename
CompiledFormat
::
char_type
,
FMT_ENABLE_IF
(
!
std
::
is_base_of
<
internal
::
basic_compiled_format
,
CompiledFormat
>
::
value
)
>
FMT_ENABLE_IF
(
internal
::
is_compiled_format
<
CompiledFormat
>
::
value
)
>
std
::
basic_string
<
Char
>
format
(
const
CompiledFormat
&
cf
,
const
Args
&
...
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
cf
.
format
(
std
::
back_inserter
(
buffer
),
args
...);
...
...
@@ -517,8 +528,7 @@ std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
}
template
<
typename
OutputIt
,
typename
CompiledFormat
,
typename
...
Args
,
FMT_ENABLE_IF
(
!
std
::
is_base_of
<
internal
::
basic_compiled_format
,
CompiledFormat
>
::
value
)
>
FMT_ENABLE_IF
(
internal
::
is_compiled_format
<
CompiledFormat
>
::
value
)
>
OutputIt
format_to
(
OutputIt
out
,
const
CompiledFormat
&
cf
,
const
Args
&
...
args
)
{
return
cf
.
format
(
out
,
args
...);
...
...
@@ -549,7 +559,7 @@ std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
using
range
=
buffer_range
<
Char
>
;
using
context
=
buffer_context
<
Char
>
;
internal
::
cf
::
vformat_to
<
context
>
(
range
(
buffer
),
cf
,
{
make_format_args
<
context
>
(
args
...)}
);
make_format_args
<
context
>
(
args
...)
);
return
to_string
(
buffer
);
}
...
...
@@ -561,8 +571,8 @@ OutputIt format_to(OutputIt out, const CompiledFormat& cf,
using
char_type
=
typename
CompiledFormat
::
char_type
;
using
range
=
internal
::
output_range
<
OutputIt
,
char_type
>
;
using
context
=
format_context_t
<
OutputIt
,
char_type
>
;
return
internal
::
cf
::
vformat_to
<
context
>
(
range
(
out
),
cf
,
{
make_format_args
<
context
>
(
args
...)}
);
return
internal
::
cf
::
vformat_to
<
context
>
(
range
(
out
),
cf
,
make_format_args
<
context
>
(
args
...)
);
}
template
<
typename
OutputIt
,
typename
CompiledFormat
,
typename
...
Args
,
...
...
include/spdlog/fmt/bundled/core.h
View file @
7698bb0a
This diff is collapsed.
Click to expand it.
include/spdlog/fmt/bundled/format-inl.h
View file @
7698bb0a
This diff is collapsed.
Click to expand it.
include/spdlog/fmt/bundled/format.h
View file @
7698bb0a
This diff is collapsed.
Click to expand it.
include/spdlog/fmt/bundled/locale.h
View file @
7698bb0a
...
...
@@ -9,6 +9,7 @@
#define FMT_LOCALE_H_
#include <locale>
#include "format.h"
FMT_BEGIN_NAMESPACE
...
...
@@ -18,16 +19,16 @@ template <typename Char>
typename
buffer_context
<
Char
>::
iterator
vformat_to
(
const
std
::
locale
&
loc
,
buffer
<
Char
>&
buf
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
buffer_context
<
Char
>>
args
)
{
basic_format_args
<
buffer_context
<
type_identity_t
<
Char
>
>>
args
)
{
using
range
=
buffer_range
<
Char
>
;
return
vformat_to
<
arg_formatter
<
range
>>
(
buf
,
to_string_view
(
format_str
),
args
,
internal
::
locale_ref
(
loc
));
}
template
<
typename
Char
>
std
::
basic_string
<
Char
>
vformat
(
const
std
::
locale
&
loc
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
buffer_context
<
Char
>>
args
)
{
std
::
basic_string
<
Char
>
vformat
(
const
std
::
locale
&
loc
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
buffer_context
<
type_identity_t
<
Char
>
>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
internal
::
vformat_to
(
loc
,
buffer
,
format_str
,
args
);
return
fmt
::
to_string
(
buffer
);
...
...
@@ -37,7 +38,7 @@ std::basic_string<Char> vformat(const std::locale& loc,
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
std
::
basic_string
<
Char
>
vformat
(
const
std
::
locale
&
loc
,
const
S
&
format_str
,
basic_format_args
<
buffer_context
<
Char
>>
args
)
{
basic_format_args
<
buffer_context
<
type_identity_t
<
Char
>
>>
args
)
{
return
internal
::
vformat
(
loc
,
to_string_view
(
format_str
),
args
);
}
...
...
@@ -46,15 +47,15 @@ inline std::basic_string<Char> format(const std::locale& loc,
const
S
&
format_str
,
Args
&&
...
args
)
{
return
internal
::
vformat
(
loc
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)}
);
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)
);
}
template
<
typename
S
,
typename
OutputIt
,
typename
...
Args
,
typename
Char
=
enable_if_t
<
internal
::
is_output_iterator
<
OutputIt
>
::
value
,
char_t
<
S
>>>
inline
OutputIt
vformat_to
(
OutputIt
out
,
const
std
::
locale
&
loc
,
const
S
&
format_str
,
format_args_t
<
OutputIt
,
Char
>
args
)
{
inline
OutputIt
vformat_to
(
OutputIt
out
,
const
std
::
locale
&
loc
,
const
S
&
format_str
,
format_args_t
<
type_identity_t
<
OutputIt
>
,
Char
>
args
)
{
using
range
=
internal
::
output_range
<
OutputIt
,
Char
>
;
return
vformat_to
<
arg_formatter
<
range
>>
(
range
(
out
),
to_string_view
(
format_str
),
args
,
internal
::
locale_ref
(
loc
));
...
...
include/spdlog/fmt/bundled/ostream.h
View file @
7698bb0a
...
...
@@ -93,7 +93,9 @@ void format_value(buffer<Char>& buf, const T& value,
locale_ref
loc
=
locale_ref
())
{
formatbuf
<
Char
>
format_buf
(
buf
);
std
::
basic_ostream
<
Char
>
output
(
&
format_buf
);
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
if
(
loc
)
output
.
imbue
(
loc
.
get
<
std
::
locale
>
());
#endif
output
.
exceptions
(
std
::
ios_base
::
failbit
|
std
::
ios_base
::
badbit
);
output
<<
value
;
buf
.
resize
(
buf
.
size
());
...
...
@@ -115,7 +117,7 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
template
<
typename
Char
>
void
vprint
(
std
::
basic_ostream
<
Char
>&
os
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
buffer_context
<
Char
>>
args
)
{
basic_format_args
<
buffer_context
<
type_identity_t
<
Char
>
>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
internal
::
vformat_to
(
buffer
,
format_str
,
args
);
internal
::
write
(
os
,
buffer
);
...
...
@@ -134,7 +136,7 @@ template <typename S, typename... Args,
typename
Char
=
enable_if_t
<
internal
::
is_string
<
S
>
::
value
,
char_t
<
S
>>>
void
print
(
std
::
basic_ostream
<
Char
>&
os
,
const
S
&
format_str
,
Args
&&
...
args
)
{
vprint
(
os
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)}
);
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)
);
}
FMT_END_NAMESPACE
...
...
include/spdlog/fmt/bundled/posix.h
View file @
7698bb0a
// A C++ interface to POSIX functions.
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
#ifndef FMT_POSIX_H_
#define FMT_POSIX_H_
#if defined(__MINGW32__) || defined(__CYGWIN__)
// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/.
# undef __STRICT_ANSI__
#endif
#include <cerrno>
#include <clocale> // for locale_t
#include <cstdio>
#include <cstdlib> // for strtod_l
#include <cstddef>
#if defined __APPLE__ || defined(__FreeBSD__)
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
#endif
#include "format.h"
// UWP doesn't provide _pipe.
#if FMT_HAS_INCLUDE("winapifamily.h")
# include <winapifamily.h>
#endif
#if FMT_HAS_INCLUDE("fcntl.h") && \
(!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
# include <fcntl.h> // for O_RDONLY
# define FMT_USE_FCNTL 1
#else
# define FMT_USE_FCNTL 0
#endif
#ifndef FMT_POSIX
# if defined(_WIN32) && !defined(__MINGW32__)
// Fix warnings about deprecated symbols.
# define FMT_POSIX(call) _##call
# else
# define FMT_POSIX(call) call
# endif
#endif
// Calls to system functions are wrapped in FMT_SYSTEM for testability.
#ifdef FMT_SYSTEM
# define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
#else
# define FMT_SYSTEM(call) call
# ifdef _WIN32
// Fix warnings about deprecated symbols.
# define FMT_POSIX_CALL(call) ::_##call
# else
# define FMT_POSIX_CALL(call) ::call
# endif
#endif
// Retries the expression while it evaluates to error_result and errno
// equals to EINTR.
#ifndef _WIN32
# define FMT_RETRY_VAL(result, expression, error_result) \
do { \
(result) = (expression); \
} while ((result) == (error_result) && errno == EINTR)
#else
# define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
#endif
#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
FMT_BEGIN_NAMESPACE
/**
\rst
A reference to a null-terminated string. It can be constructed from a C
string or ``std::string``.
You can use one of the following type aliases for common character types:
+---------------+-----------------------------+
| Type | Definition |
+===============+=============================+
| cstring_view | basic_cstring_view<char> |
+---------------+-----------------------------+
| wcstring_view | basic_cstring_view<wchar_t> |
+---------------+-----------------------------+
This class is most useful as a parameter type to allow passing
different types of strings to a function, for example::
template <typename... Args>
std::string format(cstring_view format_str, const Args & ... args);
format("{}", 42);
format(std::string("{}"), 42);
\endrst
*/
template
<
typename
Char
>
class
basic_cstring_view
{
private:
const
Char
*
data_
;
public:
/** Constructs a string reference object from a C string. */
basic_cstring_view
(
const
Char
*
s
)
:
data_
(
s
)
{}
/**
\rst
Constructs a string reference from an ``std::string`` object.
\endrst
*/
basic_cstring_view
(
const
std
::
basic_string
<
Char
>&
s
)
:
data_
(
s
.
c_str
())
{}
/** Returns the pointer to a C string. */
const
Char
*
c_str
()
const
{
return
data_
;
}
};
using
cstring_view
=
basic_cstring_view
<
char
>
;
using
wcstring_view
=
basic_cstring_view
<
wchar_t
>
;
// An error code.
class
error_code
{
private:
int
value_
;
public:
explicit
error_code
(
int
value
=
0
)
FMT_NOEXCEPT
:
value_
(
value
)
{}
int
get
()
const
FMT_NOEXCEPT
{
return
value_
;
}
};
// A buffered file.
class
buffered_file
{
private:
FILE
*
file_
;
friend
class
file
;
explicit
buffered_file
(
FILE
*
f
)
:
file_
(
f
)
{}
public:
buffered_file
(
const
buffered_file
&
)
=
delete
;
void
operator
=
(
const
buffered_file
&
)
=
delete
;
// Constructs a buffered_file object which doesn't represent any file.
buffered_file
()
FMT_NOEXCEPT
:
file_
(
nullptr
)
{}
// Destroys the object closing the file it represents if any.
FMT_API
~
buffered_file
()
FMT_NOEXCEPT
;
public:
buffered_file
(
buffered_file
&&
other
)
FMT_NOEXCEPT
:
file_
(
other
.
file_
)
{
other
.
file_
=
nullptr
;
}
buffered_file
&
operator
=
(
buffered_file
&&
other
)
{
close
();
file_
=
other
.
file_
;
other
.
file_
=
nullptr
;
return
*
this
;
}
// Opens a file.
FMT_API
buffered_file
(
cstring_view
filename
,
cstring_view
mode
);
// Closes the file.
FMT_API
void
close
();
// Returns the pointer to a FILE object representing this file.
FILE
*
get
()
const
FMT_NOEXCEPT
{
return
file_
;
}
// We place parentheses around fileno to workaround a bug in some versions
// of MinGW that define fileno as a macro.
FMT_API
int
(
fileno
)()
const
;
void
vprint
(
string_view
format_str
,
format_args
args
)
{
fmt
::
vprint
(
file_
,
format_str
,
args
);
}
template
<
typename
...
Args
>
inline
void
print
(
string_view
format_str
,
const
Args
&
...
args
)
{
vprint
(
format_str
,
make_format_args
(
args
...));
}
};
#if FMT_USE_FCNTL
// A file. Closed file is represented by a file object with descriptor -1.
// Methods that are not declared with FMT_NOEXCEPT may throw
// fmt::system_error in case of failure. Note that some errors such as
// closing the file multiple times will cause a crash on Windows rather
// than an exception. You can get standard behavior by overriding the
// invalid parameter handler with _set_invalid_parameter_handler.
class
file
{
private:
int
fd_
;
// File descriptor.
// Constructs a file object with a given descriptor.
explicit
file
(
int
fd
)
:
fd_
(
fd
)
{}
public:
// Possible values for the oflag argument to the constructor.
enum
{
RDONLY
=
FMT_POSIX
(
O_RDONLY
),
// Open for reading only.
WRONLY
=
FMT_POSIX
(
O_WRONLY
),
// Open for writing only.
RDWR
=
FMT_POSIX
(
O_RDWR
)
// Open for reading and writing.
};
// Constructs a file object which doesn't represent any file.
file
()
FMT_NOEXCEPT
:
fd_
(
-
1
)
{}
// Opens a file and constructs a file object representing this file.
FMT_API
file
(
cstring_view
path
,
int
oflag
);
public:
file
(
const
file
&
)
=
delete
;
void
operator
=
(
const
file
&
)
=
delete
;
file
(
file
&&
other
)
FMT_NOEXCEPT
:
fd_
(
other
.
fd_
)
{
other
.
fd_
=
-
1
;
}
file
&
operator
=
(
file
&&
other
)
FMT_NOEXCEPT
{
close
();
fd_
=
other
.
fd_
;
other
.
fd_
=
-
1
;
return
*
this
;
}
// Destroys the object closing the file it represents if any.
FMT_API
~
file
()
FMT_NOEXCEPT
;
// Returns the file descriptor.
int
descriptor
()
const
FMT_NOEXCEPT
{
return
fd_
;
}
// Closes the file.
FMT_API
void
close
();
// Returns the file size. The size has signed type for consistency with
// stat::st_size.
FMT_API
long
long
size
()
const
;
// Attempts to read count bytes from the file into the specified buffer.
FMT_API
std
::
size_t
read
(
void
*
buffer
,
std
::
size_t
count
);
// Attempts to write count bytes from the specified buffer to the file.
FMT_API
std
::
size_t
write
(
const
void
*
buffer
,
std
::
size_t
count
);
// Duplicates a file descriptor with the dup function and returns
// the duplicate as a file object.
FMT_API
static
file
dup
(
int
fd
);
// Makes fd be the copy of this file descriptor, closing fd first if
// necessary.
FMT_API
void
dup2
(
int
fd
);
// Makes fd be the copy of this file descriptor, closing fd first if
// necessary.
FMT_API
void
dup2
(
int
fd
,
error_code
&
ec
)
FMT_NOEXCEPT
;
// Creates a pipe setting up read_end and write_end file objects for reading
// and writing respectively.
FMT_API
static
void
pipe
(
file
&
read_end
,
file
&
write_end
);
// Creates a buffered_file object associated with this file and detaches
// this file object from the file.
FMT_API
buffered_file
fdopen
(
const
char
*
mode
);
};
// Returns the memory page size.
long
getpagesize
();
#endif // FMT_USE_FCNTL
#ifdef FMT_LOCALE
// A "C" numeric locale.
class
Locale
{
private:
# ifdef _WIN32
using
locale_t
=
_locale_t
;
enum
{
LC_NUMERIC_MASK
=
LC_NUMERIC
};
static
locale_t
newlocale
(
int
category_mask
,
const
char
*
locale
,
locale_t
)
{
return
_create_locale
(
category_mask
,
locale
);
}
static
void
freelocale
(
locale_t
locale
)
{
_free_locale
(
locale
);
}
static
double
strtod_l
(
const
char
*
nptr
,
char
**
endptr
,
_locale_t
locale
)
{
return
_strtod_l
(
nptr
,
endptr
,
locale
);
}
# endif
locale_t
locale_
;
public:
using
type
=
locale_t
;
Locale
(
const
Locale
&
)
=
delete
;
void
operator
=
(
const
Locale
&
)
=
delete
;
Locale
()
:
locale_
(
newlocale
(
LC_NUMERIC_MASK
,
"C"
,
nullptr
))
{
if
(
!
locale_
)
FMT_THROW
(
system_error
(
errno
,
"cannot create locale"
));
}
~
Locale
()
{
freelocale
(
locale_
);
}
type
get
()
const
{
return
locale_
;
}
// Converts string to floating-point number and advances str past the end
// of the parsed input.
double
strtod
(
const
char
*&
str
)
const
{
char
*
end
=
nullptr
;
double
result
=
strtod_l
(
str
,
&
end
,
locale_
);
str
=
end
;
return
result
;
}
};
#endif // FMT_LOCALE
FMT_END_NAMESPACE
#endif // FMT_POSIX_H_
#include "os.h"
#warning "fmt/posix.h is deprecated; use fmt/os.h instead"
\ No newline at end of file
include/spdlog/fmt/bundled/printf.h
View file @
7698bb0a
...
...
@@ -28,7 +28,7 @@ template <bool IsSigned> struct int_checker {
template
<
>
struct
int_checker
<
true
>
{
template
<
typename
T
>
static
bool
fits_in_int
(
T
value
)
{
return
value
>=
std
::
numeric_limits
<
int
>::
min
()
&&
return
value
>=
(
std
::
numeric_limits
<
int
>::
min
)
()
&&
value
<=
max_value
<
int
>
();
}
static
bool
fits_in_int
(
int
)
{
return
true
;
}
...
...
@@ -303,6 +303,8 @@ class printf_arg_formatter : public internal::arg_formatter_base<Range> {
};
template
<
typename
T
>
struct
printf_formatter
{
printf_formatter
()
=
delete
;
template
<
typename
ParseContext
>
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
return
ctx
.
begin
();
...
...
@@ -320,6 +322,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
public:
/** The character type for the output. */
using
char_type
=
Char
;
using
iterator
=
OutputIt
;
using
format_arg
=
basic_format_arg
<
basic_printf_context
>
;
template
<
typename
T
>
using
formatter_type
=
printf_formatter
<
T
>
;
...
...
@@ -355,6 +358,8 @@ template <typename OutputIt, typename Char> class basic_printf_context {
OutputIt
out
()
{
return
out_
;
}
void
advance_to
(
OutputIt
it
)
{
out_
=
it
;
}
internal
::
locale_ref
locale
()
{
return
{};
}
format_arg
arg
(
int
id
)
const
{
return
args_
.
get
(
id
);
}
basic_format_parse_context
<
Char
>&
parse_context
()
{
return
parse_ctx_
;
}
...
...
@@ -406,8 +411,9 @@ basic_printf_context<OutputIt, Char>::get_arg(int arg_index) {
}
template
<
typename
OutputIt
,
typename
Char
>
int
basic_printf_context
<
OutputIt
,
Char
>::
parse_header
(
const
Char
*&
it
,
const
Char
*
end
,
format_specs
&
specs
)
{
int
basic_printf_context
<
OutputIt
,
Char
>::
parse_header
(
const
Char
*&
it
,
const
Char
*
end
,
format_specs
&
specs
)
{
int
arg_index
=
-
1
;
char_type
c
=
*
it
;
if
(
c
>=
'0'
&&
c
<=
'9'
)
{
...
...
@@ -476,8 +482,8 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
specs
.
precision
=
parse_nonnegative_int
(
it
,
end
,
eh
);
}
else
if
(
c
==
'*'
)
{
++
it
;
specs
.
precision
=
static_cast
<
int
>
(
visit_format_arg
(
internal
::
printf_precision_handler
(),
get_arg
()));
specs
.
precision
=
static_cast
<
int
>
(
visit_format_arg
(
internal
::
printf_precision_handler
(),
get_arg
()));
}
else
{
specs
.
precision
=
0
;
}
...
...
@@ -596,7 +602,8 @@ inline format_arg_store<wprintf_context, Args...> make_wprintf_args(
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
std
::
basic_string
<
Char
>
vsprintf
(
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
type_identity_t
<
Char
>>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
to_string_view
(
format
),
args
);
return
to_string
(
buffer
);
...
...
@@ -615,12 +622,13 @@ template <typename S, typename... Args,
typename
Char
=
enable_if_t
<
internal
::
is_string
<
S
>
::
value
,
char_t
<
S
>>>
inline
std
::
basic_string
<
Char
>
sprintf
(
const
S
&
format
,
const
Args
&
...
args
)
{
using
context
=
basic_printf_context_t
<
Char
>
;
return
vsprintf
(
to_string_view
(
format
),
{
make_format_args
<
context
>
(
args
...)}
);
return
vsprintf
(
to_string_view
(
format
),
make_format_args
<
context
>
(
args
...)
);
}
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
int
vfprintf
(
std
::
FILE
*
f
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
inline
int
vfprintf
(
std
::
FILE
*
f
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
type_identity_t
<
Char
>>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
to_string_view
(
format
),
args
);
std
::
size_t
size
=
buffer
.
size
();
...
...
@@ -643,12 +651,13 @@ template <typename S, typename... Args,
inline
int
fprintf
(
std
::
FILE
*
f
,
const
S
&
format
,
const
Args
&
...
args
)
{
using
context
=
basic_printf_context_t
<
Char
>
;
return
vfprintf
(
f
,
to_string_view
(
format
),
{
make_format_args
<
context
>
(
args
...)}
);
make_format_args
<
context
>
(
args
...)
);
}
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
int
vprintf
(
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
inline
int
vprintf
(
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
type_identity_t
<
Char
>>>
args
)
{
return
vfprintf
(
stdout
,
to_string_view
(
format
),
args
);
}
...
...
@@ -666,12 +675,13 @@ template <typename S, typename... Args,
inline
int
printf
(
const
S
&
format_str
,
const
Args
&
...
args
)
{
using
context
=
basic_printf_context_t
<
char_t
<
S
>>
;
return
vprintf
(
to_string_view
(
format_str
),
{
make_format_args
<
context
>
(
args
...)}
);
make_format_args
<
context
>
(
args
...)
);
}
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
int
vfprintf
(
std
::
basic_ostream
<
Char
>&
os
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
inline
int
vfprintf
(
std
::
basic_ostream
<
Char
>&
os
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
type_identity_t
<
Char
>>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
to_string_view
(
format
),
args
);
internal
::
write
(
os
,
buffer
);
...
...
@@ -682,9 +692,9 @@ inline int vfprintf(std::basic_ostream<Char>& os, const S& format,
template
<
typename
ArgFormatter
,
typename
Char
,
typename
Context
=
basic_printf_context
<
typename
ArgFormatter
::
iterator
,
Char
>
>
typename
ArgFormatter
::
iterator
vprintf
(
internal
::
buffer
<
Char
>&
out
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
Context
>
args
)
{
typename
ArgFormatter
::
iterator
vprintf
(
internal
::
buffer
<
Char
>&
out
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
type_identity_t
<
Context
>
>
args
)
{
typename
ArgFormatter
::
iterator
iter
(
out
);
Context
(
iter
,
format_str
,
args
).
template
format
<
ArgFormatter
>();
return
iter
;
...
...
@@ -704,7 +714,7 @@ inline int fprintf(std::basic_ostream<Char>& os, const S& format_str,
const
Args
&
...
args
)
{
using
context
=
basic_printf_context_t
<
Char
>
;
return
vfprintf
(
os
,
to_string_view
(
format_str
),
{
make_format_args
<
context
>
(
args
...)}
);
make_format_args
<
context
>
(
args
...)
);
}
FMT_END_NAMESPACE
...
...
include/spdlog/fmt/bundled/ranges.h
View file @
7698bb0a
...
...
@@ -12,7 +12,9 @@
#ifndef FMT_RANGES_H_
#define FMT_RANGES_H_
#include <initializer_list>
#include <type_traits>
#include "format.h"
// output only up to N items from the range.
...
...
@@ -104,10 +106,7 @@ struct is_range_<
/// tuple_size and tuple_element check.
template
<
typename
T
>
class
is_tuple_like_
{
template
<
typename
U
>
static
auto
check
(
U
*
p
)
->
decltype
(
std
::
tuple_size
<
U
>::
value
,
(
void
)
std
::
declval
<
typename
std
::
tuple_element
<
0
,
U
>::
type
>
(),
int
());
static
auto
check
(
U
*
p
)
->
decltype
(
std
::
tuple_size
<
U
>::
value
,
int
());
template
<
typename
>
static
void
check
(...);
public:
...
...
@@ -360,6 +359,29 @@ FMT_CONSTEXPR tuple_arg_join<wchar_t, T...> join(const std::tuple<T...>& tuple,
return
{
tuple
,
sep
};
}
/**
\rst
Returns an object that formats `initializer_list` with elements separated by
`sep`.
**Example**::
fmt::print("{}", fmt::join({1, 2, 3}, ", "));
// Output: "1, 2, 3"
\endrst
*/
template
<
typename
T
>
arg_join
<
internal
::
iterator_t
<
const
std
::
initializer_list
<
T
>>
,
char
>
join
(
std
::
initializer_list
<
T
>
list
,
string_view
sep
)
{
return
join
(
std
::
begin
(
list
),
std
::
end
(
list
),
sep
);
}
template
<
typename
T
>
arg_join
<
internal
::
iterator_t
<
const
std
::
initializer_list
<
T
>>
,
wchar_t
>
join
(
std
::
initializer_list
<
T
>
list
,
wstring_view
sep
)
{
return
join
(
std
::
begin
(
list
),
std
::
end
(
list
),
sep
);
}
FMT_END_NAMESPACE
#endif // FMT_RANGES_H_
src/fmt.cpp
View file @
7698bb0a
This diff is collapsed.
Click to expand it.
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