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
d142579e
Commit
d142579e
authored
Jun 02, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup the format API
parent
f286139d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
20 deletions
+19
-20
include/fmt/format.h
include/fmt/format.h
+18
-19
include/fmt/xchar.h
include/fmt/xchar.h
+1
-1
No files found.
include/fmt/format.h
View file @
d142579e
...
@@ -2237,7 +2237,7 @@ FMT_API std::system_error vsystem_error(int error_code, string_view format_str,
...
@@ -2237,7 +2237,7 @@ FMT_API std::system_error vsystem_error(int error_code, string_view format_str,
/**
/**
\rst
\rst
Constructs :class:`std::system_error` with a message formatted with
Constructs :class:`std::system_error` with a message formatted with
``fmt::format(
message
, args...)``.
``fmt::format(
fmt
, args...)``.
*error_code* is a system error code as given by ``errno``.
*error_code* is a system error code as given by ``errno``.
**Example**::
**Example**::
...
@@ -2251,10 +2251,10 @@ FMT_API std::system_error vsystem_error(int error_code, string_view format_str,
...
@@ -2251,10 +2251,10 @@ FMT_API std::system_error vsystem_error(int error_code, string_view format_str,
throw fmt::system_error(errno, "cannot open file '{}'", filename);
throw fmt::system_error(errno, "cannot open file '{}'", filename);
\endrst
\endrst
*/
*/
template
<
typename
...
Args
>
template
<
typename
...
T
>
std
::
system_error
system_error
(
int
error_code
,
string_view
message
,
auto
system_error
(
int
error_code
,
format_string
<
T
...
>
fmt
,
T
&&
...
args
)
const
Args
&
...
args
)
{
->
std
::
system_error
{
return
vsystem_error
(
error_code
,
message
,
fmt
::
make_format_args
(
args
...));
return
vsystem_error
(
error_code
,
fmt
,
fmt
::
make_format_args
(
args
...));
}
}
/**
/**
...
@@ -2413,12 +2413,22 @@ struct formatter<Char[N], Char> : formatter<basic_string_view<Char>, Char> {
...
@@ -2413,12 +2413,22 @@ struct formatter<Char[N], Char> : formatter<basic_string_view<Char>, Char> {
// };
// };
template
<
typename
Char
=
char
>
class
dynamic_formatter
{
template
<
typename
Char
=
char
>
class
dynamic_formatter
{
private:
private:
detail
::
dynamic_format_specs
<
Char
>
specs_
;
const
Char
*
format_str_
;
struct
null_handler
:
detail
::
error_handler
{
struct
null_handler
:
detail
::
error_handler
{
void
on_align
(
align_t
)
{}
void
on_align
(
align_t
)
{}
void
on_sign
(
sign_t
)
{}
void
on_sign
(
sign_t
)
{}
void
on_hash
()
{}
void
on_hash
()
{}
};
};
template
<
typename
Context
>
void
handle_specs
(
Context
&
ctx
)
{
detail
::
handle_dynamic_spec
<
detail
::
width_checker
>
(
specs_
.
width
,
specs_
.
width_ref
,
ctx
);
detail
::
handle_dynamic_spec
<
detail
::
precision_checker
>
(
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
);
}
public:
public:
template
<
typename
ParseContext
>
template
<
typename
ParseContext
>
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
...
@@ -2439,17 +2449,6 @@ template <typename Char = char> class dynamic_formatter {
...
@@ -2439,17 +2449,6 @@ template <typename Char = char> class dynamic_formatter {
if
(
specs_
.
precision
>=
0
)
checker
.
end_precision
();
if
(
specs_
.
precision
>=
0
)
checker
.
end_precision
();
return
detail
::
write
<
Char
>
(
ctx
.
out
(),
val
,
specs_
,
ctx
.
locale
());
return
detail
::
write
<
Char
>
(
ctx
.
out
(),
val
,
specs_
,
ctx
.
locale
());
}
}
private:
template
<
typename
Context
>
void
handle_specs
(
Context
&
ctx
)
{
detail
::
handle_dynamic_spec
<
detail
::
width_checker
>
(
specs_
.
width
,
specs_
.
width_ref
,
ctx
);
detail
::
handle_dynamic_spec
<
detail
::
precision_checker
>
(
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
);
}
detail
::
dynamic_format_specs
<
Char
>
specs_
;
const
Char
*
format_str_
;
};
};
/**
/**
...
@@ -2461,14 +2460,14 @@ template <typename Char = char> class dynamic_formatter {
...
@@ -2461,14 +2460,14 @@ template <typename Char = char> class dynamic_formatter {
auto s = fmt::format("{}", fmt::ptr(p));
auto s = fmt::format("{}", fmt::ptr(p));
\endrst
\endrst
*/
*/
template
<
typename
T
>
const
void
*
ptr
(
T
p
)
{
template
<
typename
T
>
auto
ptr
(
T
p
)
->
const
void
*
{
static_assert
(
std
::
is_pointer
<
T
>::
value
,
""
);
static_assert
(
std
::
is_pointer
<
T
>::
value
,
""
);
return
detail
::
bit_cast
<
const
void
*>
(
p
);
return
detail
::
bit_cast
<
const
void
*>
(
p
);
}
}
template
<
typename
T
>
const
void
*
ptr
(
const
std
::
unique_ptr
<
T
>&
p
)
{
template
<
typename
T
>
auto
ptr
(
const
std
::
unique_ptr
<
T
>&
p
)
->
const
void
*
{
return
p
.
get
();
return
p
.
get
();
}
}
template
<
typename
T
>
const
void
*
ptr
(
const
std
::
shared_ptr
<
T
>&
p
)
{
template
<
typename
T
>
auto
ptr
(
const
std
::
shared_ptr
<
T
>&
p
)
->
const
void
*
{
return
p
.
get
();
return
p
.
get
();
}
}
...
...
include/fmt/xchar.h
View file @
d142579e
...
@@ -183,7 +183,7 @@ inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) {
...
@@ -183,7 +183,7 @@ inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) {
detail
::
vformat_to
(
buffer
,
fmt
,
args
);
detail
::
vformat_to
(
buffer
,
fmt
,
args
);
buffer
.
push_back
(
L'\0'
);
buffer
.
push_back
(
L'\0'
);
if
(
std
::
fputws
(
buffer
.
data
(),
f
)
==
-
1
)
if
(
std
::
fputws
(
buffer
.
data
(),
f
)
==
-
1
)
FMT_THROW
(
system_error
(
errno
,
"cannot write to file"
));
FMT_THROW
(
system_error
(
errno
,
FMT_STRING
(
"cannot write to file"
)
));
}
}
inline
void
vprint
(
wstring_view
fmt
,
wformat_args
args
)
{
inline
void
vprint
(
wstring_view
fmt
,
wformat_args
args
)
{
...
...
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