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
3a7962fc
Commit
3a7962fc
authored
Sep 04, 2013
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the docs.
parent
9aa5b7ec
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
52 deletions
+76
-52
README.rst
README.rst
+2
-2
doc/Doxyfile
doc/Doxyfile
+1
-0
doc/index.rst
doc/index.rst
+4
-1
format.h
format.h
+69
-49
No files found.
README.rst
View file @
3a7962fc
...
...
@@ -81,8 +81,8 @@ with an arbitrary action performed when formatting is complete:
.. code-block:: c++
struct PrintError {
void operator()(const fmt::
Formatter &f
) const {
std::cerr << "Error: " <<
f
.str() << std::endl;
void operator()(const fmt::
Writer &w
) const {
std::cerr << "Error: " <<
w
.str() << std::endl;
}
};
...
...
doc/Doxyfile
View file @
3a7962fc
...
...
@@ -6,6 +6,7 @@ CASE_SENSE_NAMES = NO
INPUT = ../format.h
QUIET = YES
JAVADOC_AUTOBRIEF = YES
AUTOLINK_SUPPORT = NO
GENERATE_HTML = NO
GENERATE_XML = YES
XML_OUTPUT = doxyxml
...
...
doc/index.rst
View file @
3a7962fc
...
...
@@ -7,7 +7,7 @@ String Formatting API
.. doxygenfunction:: fmt::Format(StringRef)
.. doxygenclass:: fmt::Basic
Format
ter
.. doxygenclass:: fmt::Basic
Wri
ter
:members:
.. doxygenclass:: fmt::Formatter
...
...
@@ -16,6 +16,9 @@ String Formatting API
.. doxygenclass:: fmt::NoAction
:members:
.. doxygenclass:: fmt::Write
:members:
.. doxygenclass:: fmt::StringRef
:members:
...
...
format.h
View file @
3a7962fc
...
...
@@ -243,7 +243,7 @@ class FormatterProxy;
Format(std::string("{}")) << 42;
Format(Format("{{}}")) << 42;
\endrst
*/
*/
class
StringRef
{
private:
const
char
*
data_
;
...
...
@@ -391,7 +391,7 @@ IntFormatter<int, TypeSpec<'X'> > hexu(int value);
**Example**::
std::string s = str(
Basic
Writer() << pad(hex(0xcafe), 8, '0'));
std::string s = str(Writer() << pad(hex(0xcafe), 8, '0'));
// s == "0000cafe"
\endrst
...
...
@@ -435,6 +435,11 @@ DEFINE_INT_FORMATTERS(unsigned long)
template
<
typename
Char
>
class
BasicFormatter
;
/**
This template provides operations for formatting and writing data into
a character stream. The output is stored in a memory buffer that grows
dynamically.
*/
template
<
typename
Char
>
class
BasicWriter
{
private:
...
...
@@ -546,9 +551,26 @@ class BasicWriter {
}
/**
Formats a string appending the output to the internal buffer.
Arguments are accepted through the returned `BasicFormatter` object
using inserter operator `<<`.
\rst
Formats a string sending the output to the writer. Arguments are
accepted through the returned `BasicFormatter` object using inserter
operator `<<`.
**Example**::
Writer out;
out.Format("Current point:\n");
out.Format("({:+f}, {:+f})") << -3.14 << 3.14;
This will write the following output to the ``out`` object:
.. code-block:: none
Current point:
(-3.140000, +3.140000)
The output can be accessed using :meth:`data` or :meth:`c_str`.
\endrst
*/
BasicFormatter
<
Char
>
Format
(
StringRef
format
);
...
...
@@ -896,27 +918,8 @@ void FormatCustomArg(
The :cpp:class:`fmt::BasicFormatter` template provides string formatting
functionality similar to Python's `str.format
<http://docs.python.org/3/library/stdtypes.html#str.format>`__.
The output is stored in a memory buffer that grows dynamically.
The class provides operator<< for feeding formatting arguments.
**Example**::
Formatter out;
out("Current point:\n");
out("({:+f}, {:+f})") << -3.14 << 3.14;
This will populate the buffer of the ``out`` object with the following
output:
.. code-block:: none
Current point:
(-3.140000, +3.140000)
The buffer can be accessed using :meth:`data` or :meth:`c_str`.
Objects of this class normally exists only as temporaries returned
by one of the formatting functions.
The class provides operator<< for feeding formatting arguments and all
the output is sent to a :cpp:class:`fmt::Writer` object.
\endrst
*/
template
<
typename
Char
>
...
...
@@ -1076,9 +1079,8 @@ class BasicFormatter {
}
public
:
/**
Constructs a formatter with an empty output buffer.
*/
// Constructs a formatter with a writer to be used for output and a format
// format string.
BasicFormatter
(
BasicWriter
<
Char
>
&
w
,
const
Char
*
format
=
0
)
:
writer_
(
&
w
),
format_
(
format
)
{}
...
...
@@ -1086,9 +1088,7 @@ class BasicFormatter {
CompleteFormatting
();
}
/**
Constructs a formatter from a proxy object.
*/
// Constructs a formatter from a proxy object.
BasicFormatter
(
const
Proxy
&
p
)
:
BasicFormatter
<
Char
>
(
*
p
.
writer
,
p
.
format
)
{}
operator
Proxy
()
{
...
...
@@ -1171,16 +1171,30 @@ class NoAction {
};
/**
\rst
A formatter with an action performed when formatting is complete.
Objects of this class normally exist only as temporaries returned
by one of the formatting functions.
by one of the formatting functions. You can use this class to create
your own functions similar to :cpp:func:`fmt::Format()`.
**Example**::
struct PrintError {
void operator()(const fmt::Writer &w) const {
std::cerr << "Error: " << w.str() << std::endl;
}
};
// Formats an error message and prints it to std::cerr.
fmt::Formatter<PrintError> ReportError(const char *format) {
return fmt::Formatter<PrintError>(format);
}
ReportError("File not found: {}") << path;
\endrst
*/
template
<
typename
Action
=
NoAction
,
typename
Char
=
char
>
class
Formatter
:
private
Action
,
public
BasicFormatter
<
Char
>
{
private:
friend
class
fmt
::
BasicFormatter
<
Char
>
;
friend
class
fmt
::
StringRef
;
private:
BasicWriter
<
Char
>
writer_
;
bool
inactive_
;
...
...
@@ -1201,7 +1215,7 @@ class Formatter : private Action, public BasicFormatter<Char> {
\rst
Constructs a formatter with a format string and an action.
The action should be an unary function object that takes a const
reference to :cpp:class:`fmt::Basic
Format
ter` as an argument.
reference to :cpp:class:`fmt::Basic
Wri
ter` as an argument.
See :cpp:class:`fmt::NoAction` and :cpp:class:`fmt::Write` for
examples of action classes.
\endrst
...
...
@@ -1240,13 +1254,17 @@ class Formatter : private Action, public BasicFormatter<Char> {
/**
\rst
Formats a string. Returns a temporary formatter object that accepts
arguments via operator ``<<``. *format* is a format string that contains
literal text and replacement fields surrounded by braces ``{}``.
The formatter object replaces the fields with formatted arguments
and stores the output in a memory buffer. The content of the buffer can
be converted to ``std::string`` with :cpp:func:`fmt::str()` or
accessed as a C string with :cpp:func:`fmt::c_str()`.
Formats a string similarly to Python's `str.format
<http://docs.python.org/3/library/stdtypes.html#str.format>`__.
Returns a temporary formatter object that accepts arguments via
operator ``<<``.
*format* is a format string that contains literal text and replacement
fields surrounded by braces ``{}``. The formatter object replaces the
fields with formatted arguments and stores the output in a memory buffer.
The content of the buffer can be converted to ``std::string`` with
:cpp:func:`fmt::str()` or accessed as a C string with
:cpp:func:`fmt::c_str()`.
**Example**::
...
...
@@ -1259,8 +1277,10 @@ inline Formatter<> Format(StringRef format) {
return
Formatter
<>
(
format
);
}
// A formatting action that writes formatted output to stdout.
struct
Write
{
/** A formatting action that writes formatted output to stdout. */
class
Write
{
public:
/** Write the output to stdout. */
void
operator
()(
const
BasicWriter
<
char
>
&
w
)
const
{
std
::
fwrite
(
w
.
data
(),
1
,
w
.
size
(),
stdout
);
}
...
...
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