<commit_before>.. _string-formatting-api:

*************
API Reference
*************

All functions and classes provided by the fmt library reside
in namespace ``fmt`` and macros have prefix ``FMT_``. For brevity the
namespace is usually omitted in examples.

Format API
==========

The following functions use :ref:`format string syntax <syntax>` similar
to the one used by Python's `str.format
<http://docs.python.org/3/library/stdtypes.html#str.format>`_ function.
They take *format_str* and *args* as arguments.

*format_str* is a format string that contains literal text and replacement
fields surrounded by braces ``{}``. The fields are replaced with formatted
arguments in the resulting string.

*args* is an argument list representing arbitrary arguments.

.. _format:

.. doxygenfunction:: format(CStringRef, ArgList)

.. doxygenfunction:: operator""_format(const char *, std::size_t)

.. _print:

.. doxygenfunction:: print(CStringRef, ArgList)

.. doxygenfunction:: print(std::FILE *, CStringRef, ArgList)

.. doxygenfunction:: print(std::ostream&, CStringRef, ArgList)

.. doxygenclass:: fmt::BasicFormatter
   :members:

Date and time formatting
------------------------

The library supports [strftime](http://en.cppreference.com/w/cpp/chrono/c/strftime)-like
date and time formatting::

  #include "fmt/time.h"

  std::time_t t = std::time(nullptr);
  // Prints "The date is 2016-04-29." (with the current date)
  fmt::print("The date is {:%Y-%m-%d}.", *std::localtime(&t));

The format string syntax is described in the documentation of
[strftime](http://en.cppreference.com/w/cpp/chrono/c/strftime).

Argument formatters
-------------------

It is possible to change the way arguments are formatted by providing a
custom argument formatter class::

  // A custom argument formatter that formats negative integers as unsigned
  // with the ``x`` format specifier.
  class CustomArgFormatter :<commit_msg>Correct formatting<commit_after>.. _string-formatting-api:

*************
API Reference
*************

All functions and classes provided by the fmt library reside
in namespace ``fmt`` and macros have prefix ``FMT_``. For brevity the
namespace is usually omitted in examples.

Format API
==========

The following functions use :ref:`format string syntax <syntax>` similar
to the one used by Python's `str.format
<http://docs.python.org/3/library/stdtypes.html#str.format>`_ function.
They take *format_str* and *args* as arguments.

*format_str* is a format string that contains literal text and replacement
fields surrounded by braces ``{}``. The fields are replaced with formatted
arguments in the resulting string.

*args* is an argument list representing arbitrary arguments.

.. _format:

.. doxygenfunction:: format(CStringRef, ArgList)

.. doxygenfunction:: operator""_format(const char *, std::size_t)

.. _print:

.. doxygenfunction:: print(CStringRef, ArgList)

.. doxygenfunction:: print(std::FILE *, CStringRef, ArgList)

.. doxygenfunction:: print(std::ostream&, CStringRef, ArgList)

.. doxygenclass:: fmt::BasicFormatter
   :members:

Date and time formatting
------------------------

The library supports `strftime <http://en.cppreference.com/w/cpp/chrono/c/strftime>`_-like
date and time formatting::

  #include "fmt/time.h"

  std::time_t t = std::time(nullptr);
  // Prints "The date is 2016-04-29." (with the current date)
  fmt::print("The date is {:%Y-%m-%d}.", *std::localtime(&t));

The format string syntax is described in the documentation of
`strftime <http://en.cppreference.com/w/cpp/chrono/c/strftime>`_.

Argument formatters
-------------------

It is possible to change the way arguments are formatted by providing a
custom argument formatter class::

  // A custom argument formatter that formats negative integers as unsigned
  // with the ``x`` format specifier.
  class CustomArgFormatter :
{'fraction_non_alphanumeric': 0.1506884905170174, 'fraction_numerical': 0.004676539360872954, 'mean_word_length': 4.2168021680216805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4384869', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1075, 'n_words': 389}