forked from fmtlib/fmt
Update docs
This commit is contained in:
@ -42,8 +42,8 @@ Features
|
|||||||
performance of IOStreams. See `Speed tests`_ and
|
performance of IOStreams. See `Speed tests`_ and
|
||||||
`Fast integer to string conversion in C++
|
`Fast integer to string conversion in C++
|
||||||
<http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_.
|
<http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_.
|
||||||
* Small code size both in terms of source code (the core library consists of a
|
* Small code size both in terms of source code (the core library consists of two
|
||||||
single header file and a single source file) and compiled code.
|
header files and a single source file) and compiled code.
|
||||||
See `Compile time and code bloat`_.
|
See `Compile time and code bloat`_.
|
||||||
* Reliability: the library has an extensive set of `unit tests
|
* Reliability: the library has an extensive set of `unit tests
|
||||||
<https://github.com/fmtlib/fmt/tree/master/test>`_.
|
<https://github.com/fmtlib/fmt/tree/master/test>`_.
|
||||||
@ -101,7 +101,7 @@ Format strings can be checked at compile time:
|
|||||||
on_error("argument index out of range");
|
on_error("argument index out of range");
|
||||||
^
|
^
|
||||||
|
|
||||||
fmt can be used as a safe portable replacement for ``itoa``:
|
{fmt} can be used as a safe portable replacement for ``itoa``:
|
||||||
|
|
||||||
.. code:: c++
|
.. code:: c++
|
||||||
|
|
||||||
|
20
doc/api.rst
20
doc/api.rst
@ -11,7 +11,7 @@ namespace is usually omitted in examples.
|
|||||||
Format API
|
Format API
|
||||||
==========
|
==========
|
||||||
|
|
||||||
The following functions defined in ``fmt/format.h`` use :ref:`format string
|
The following functions defined in ``fmt/core.h`` use :ref:`format string
|
||||||
syntax <syntax>` similar to the one used by Python's `str.format
|
syntax <syntax>` similar to the one used by 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>`_ function.
|
||||||
They take *format_str* and *args* as arguments.
|
They take *format_str* and *args* as arguments.
|
||||||
@ -71,7 +71,7 @@ template and implement ``parse`` and ``format`` methods::
|
|||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const MyStruct &s, FormatContext &ctx) {
|
auto format(const MyStruct &s, FormatContext &ctx) {
|
||||||
fmt::format_to(ctx.begin(), "[MyStruct: x={:.1f}, y={:.2f}]", s.x, s.y);
|
return format_to(ctx.begin(), "[MyStruct: x={:.1f}, y={:.2f}]", s.x, s.y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ Then you can pass objects of type ``MyStruct`` to any formatting function::
|
|||||||
|
|
||||||
In the example above the ``formatter<MyStruct>::parse`` function ignores the
|
In the example above the ``formatter<MyStruct>::parse`` function ignores the
|
||||||
contents of the format string referred to by ``ctx.begin()`` so the object will
|
contents of the format string referred to by ``ctx.begin()`` so the object will
|
||||||
always be formatted as specified. See ``formatter<tm>::parse`` in
|
always be formatted in the same way. See ``formatter<tm>::parse`` in
|
||||||
:file:`fmt/time.h` for an advanced example of how to parse the format string and
|
:file:`fmt/time.h` for an advanced example of how to parse the format string and
|
||||||
customize the formatted output.
|
customize the formatted output.
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ formatting of user-defined types that have overloaded ``operator<<``::
|
|||||||
std::string s = fmt::format("The date is {}", Date(2012, 12, 9));
|
std::string s = fmt::format("The date is {}", Date(2012, 12, 9));
|
||||||
// s == "The date is 2012-12-9"
|
// s == "The date is 2012-12-9"
|
||||||
|
|
||||||
.. doxygenfunction:: print(std::ostream&, string_view, ArgList)
|
.. doxygenfunction:: print(std::ostream&, string_view, const Args&...)
|
||||||
|
|
||||||
Argument formatters
|
Argument formatters
|
||||||
-------------------
|
-------------------
|
||||||
@ -168,13 +168,13 @@ the POSIX extension for positional arguments. Unlike their standard
|
|||||||
counterparts, the ``fmt`` functions are type-safe and throw an exception if an
|
counterparts, the ``fmt`` functions are type-safe and throw an exception if an
|
||||||
argument type doesn't match its format specification.
|
argument type doesn't match its format specification.
|
||||||
|
|
||||||
.. doxygenfunction:: printf(string_view, ArgList)
|
.. doxygenfunction:: printf(string_view, const Args&...)
|
||||||
|
|
||||||
.. doxygenfunction:: fprintf(std::FILE *, string_view, ArgList)
|
.. doxygenfunction:: fprintf(std::FILE *, string_view, const Args&...)
|
||||||
|
|
||||||
.. doxygenfunction:: fprintf(std::ostream&, string_view, ArgList)
|
.. doxygenfunction:: fprintf(std::ostream&, string_view, const Args&...)
|
||||||
|
|
||||||
.. doxygenfunction:: sprintf(string_view, ArgList)
|
.. doxygenfunction:: sprintf(string_view, const Args&...)
|
||||||
|
|
||||||
.. doxygenclass:: fmt::PrintfFormatter
|
.. doxygenclass:: fmt::PrintfFormatter
|
||||||
:members:
|
:members:
|
||||||
@ -246,12 +246,12 @@ Utilities
|
|||||||
System errors
|
System errors
|
||||||
=============
|
=============
|
||||||
|
|
||||||
.. doxygenclass:: fmt::SystemError
|
.. doxygenclass:: fmt::system_error
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
.. doxygenfunction:: fmt::format_system_error
|
.. doxygenfunction:: fmt::format_system_error
|
||||||
|
|
||||||
.. doxygenclass:: fmt::WindowsError
|
.. doxygenclass:: fmt::windows_error
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
.. _formatstrings:
|
.. _formatstrings:
|
||||||
|
@ -3233,7 +3233,7 @@ auto join(const Range &range, wstring_view sep)
|
|||||||
|
|
||||||
**Example**::
|
**Example**::
|
||||||
|
|
||||||
#include "fmt/string.h"
|
#include "fmt/format.h"
|
||||||
|
|
||||||
std::string answer = fmt::to_string(42);
|
std::string answer = fmt::to_string(42);
|
||||||
\endrst
|
\endrst
|
||||||
|
Reference in New Issue
Block a user