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
d07ba498
Commit
d07ba498
authored
Mar 03, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix docs
parent
418659ad
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
31 deletions
+32
-31
doc/api.rst
doc/api.rst
+32
-31
No files found.
doc/api.rst
View file @
d07ba498
...
@@ -4,16 +4,16 @@
...
@@ -4,16 +4,16 @@
API Reference
API Reference
*************
*************
All functions and classes provided by the fmt library reside
All functions and classes provided by the fmt library reside
in namespace
in namespace ``fmt`` and macros have prefix ``FMT_``. For brevity the
``fmt`` and macros have prefix ``FMT_``. For brevity the namespace is usually
namespace is usually
omitted in examples.
omitted in examples.
Format API
Format API
==========
==========
The following functions defined in ``fmt/core.h`` use :ref:`format string
The following functions defined in ``fmt/core.h`` use :ref:`format string
syntax <syntax>` similar to th
e one used by
Python's `str.format
syntax <syntax>` similar to th
at of
Python's `str.format
<http://docs.python.org/3/library/stdtypes.html#str.format>`_
function
.
<http://docs.python.org/3/library/stdtypes.html#str.format>`_.
They take *format_str* and *args* as arguments.
They take *format_str* and *args* as arguments.
*format_str* is a format string that contains literal text and replacement
*format_str* is a format string that contains literal text and replacement
...
@@ -25,7 +25,6 @@ arguments in the resulting string.
...
@@ -25,7 +25,6 @@ arguments in the resulting string.
The `performance of the format API
The `performance of the format API
<https://github.com/fmtlib/fmt/blob/master/README.rst#speed-tests>`_ is close
<https://github.com/fmtlib/fmt/blob/master/README.rst#speed-tests>`_ is close
to that of glibc's ``printf`` and better than the performance of IOStreams.
to that of glibc's ``printf`` and better than the performance of IOStreams.
For even better speed use the `write API`_.
.. _format:
.. _format:
...
@@ -121,41 +120,48 @@ Argument formatters
...
@@ -121,41 +120,48 @@ Argument formatters
It is possible to change the way arguments are formatted by providing a
It is possible to change the way arguments are formatted by providing a
custom argument formatter class::
custom argument formatter class::
using arg_formatter =
fmt::arg_formatter<fmt::back_insert_range<fmt::internal::buffer>>;
// A custom argument formatter that formats negative integers as unsigned
// A custom argument formatter that formats negative integers as unsigned
// with the ``x`` format specifier.
// with the ``x`` format specifier.
class CustomArgFormatter :
class custom_arg_formatter : public arg_formatter {
public fmt::BasicArgFormatter<CustomArgFormatter, char> {
public:
public:
CustomArgFormatter(fmt::BasicFormatter<char, CustomArgFormatter> &f,
custom_arg_formatter(context_type &ctx, fmt::format_specs &spec)
fmt::FormatSpec &s, const char *fmt)
: arg_formatter(ctx, spec) {}
: fmt::BasicArgFormatter<CustomArgFormatter, char>(f, s, fmt) {}
using arg_formatter::operator();
void
visit_int
(int value) {
void
operator()
(int value) {
if (spec().type() == 'x')
if (spec().type() == 'x')
visit_uint(value
); // convert to unsigned and format
(*this)(static_cast<unsigned>(value)
); // convert to unsigned and format
else
else
fmt::BasicArgFormatter<CustomArgFormatter, char>::visit_int
(value);
arg_formatter::operator()
(value);
}
}
};
};
std::string custom_format(const char *format_str, fmt::ArgList args) {
std::string custom_vformat(fmt::string_view format_str, fmt::format_args args) {
fmt::MemoryWriter writer;
fmt::memory_buffer buffer;
// Pass custom argument formatter as a template arg to BasicFormatter.
// Pass custom argument formatter as a template arg to do_vformat.
fmt::BasicFormatter<char, CustomArgFormatter> formatter(args, writer);
fmt::do_vformat_to<custom_arg_formatter>(buffer, format_str, args);
formatter.format(format_str);
return fmt::to_string(buffer);
return writer.str();
}
template <typename ...Args>
inline std::string custom_format(
fmt::string_view format_str, const Args &... args) {
return custom_vformat(format_str, fmt::make_args(args...));
}
}
FMT_VARIADIC(std::string, custom_format, const char *)
std::string s = custom_format("{:x}", -42); // s == "ffffffd6"
std::string s = custom_format("{:x}", -42); // s == "ffffffd6"
.. doxygenclass:: fmt::ArgVisitor
.. doxygenclass:: fmt::ArgVisitor
:members:
:members:
.. doxygenclass:: fmt::
BasicArgFormatter
.. doxygenclass:: fmt::
arg_formatter_base
:members:
:members:
.. doxygenclass:: fmt::
ArgF
ormatter
.. doxygenclass:: fmt::
arg_f
ormatter
:members:
:members:
Printf formatting
Printf formatting
...
@@ -211,23 +217,18 @@ store output elsewhere by subclassing `~fmt::BasicWriter`.
...
@@ -211,23 +217,18 @@ store output elsewhere by subclassing `~fmt::BasicWriter`.
Utilities
Utilities
=========
=========
.. doxygenfunction:: fmt::arg(
StringRef
, const T&)
.. doxygenfunction:: fmt::arg(
string_view
, const T&)
.. doxygenfunction:: operator""_a(const char *, std::size_t)
.. doxygenfunction:: operator""_a(const char *, std::size_t)
.. doxygendefine:: FMT_CAPTURE
.. doxygendefine:: FMT_CAPTURE
.. doxygendefine:: FMT_VARIADIC
.. doxygenclass:: fmt::basic_format_args
.. doxygenclass:: fmt::ArgList
:members:
:members:
.. doxygenfunction:: fmt::to_string(const T&)
.. doxygenfunction:: fmt::to_string(const T&)
.. doxygenclass:: fmt::BasicStringRef
.. doxygenclass:: fmt::basic_string_view
:members:
.. doxygenclass:: fmt::BasicCStringRef
:members:
:members:
.. doxygenclass:: fmt::Buffer
.. doxygenclass:: fmt::Buffer
...
...
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