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:
...
@@ -81,8 +81,8 @@ with an arbitrary action performed when formatting is complete:
.. code-block:: c++
.. code-block:: c++
struct PrintError {
struct PrintError {
void operator()(const fmt::
Formatter &f
) const {
void operator()(const fmt::
Writer &w
) const {
std::cerr << "Error: " <<
f
.str() << std::endl;
std::cerr << "Error: " <<
w
.str() << std::endl;
}
}
};
};
...
...
doc/Doxyfile
View file @
3a7962fc
...
@@ -6,6 +6,7 @@ CASE_SENSE_NAMES = NO
...
@@ -6,6 +6,7 @@ CASE_SENSE_NAMES = NO
INPUT = ../format.h
INPUT = ../format.h
QUIET = YES
QUIET = YES
JAVADOC_AUTOBRIEF = YES
JAVADOC_AUTOBRIEF = YES
AUTOLINK_SUPPORT = NO
GENERATE_HTML = NO
GENERATE_HTML = NO
GENERATE_XML = YES
GENERATE_XML = YES
XML_OUTPUT = doxyxml
XML_OUTPUT = doxyxml
...
...
doc/index.rst
View file @
3a7962fc
...
@@ -7,7 +7,7 @@ String Formatting API
...
@@ -7,7 +7,7 @@ String Formatting API
.. doxygenfunction:: fmt::Format(StringRef)
.. doxygenfunction:: fmt::Format(StringRef)
.. doxygenclass:: fmt::Basic
Format
ter
.. doxygenclass:: fmt::Basic
Wri
ter
:members:
:members:
.. doxygenclass:: fmt::Formatter
.. doxygenclass:: fmt::Formatter
...
@@ -16,6 +16,9 @@ String Formatting API
...
@@ -16,6 +16,9 @@ String Formatting API
.. doxygenclass:: fmt::NoAction
.. doxygenclass:: fmt::NoAction
:members:
:members:
.. doxygenclass:: fmt::Write
:members:
.. doxygenclass:: fmt::StringRef
.. doxygenclass:: fmt::StringRef
:members:
:members:
...
...
format.h
View file @
3a7962fc
...
@@ -243,7 +243,7 @@ class FormatterProxy;
...
@@ -243,7 +243,7 @@ class FormatterProxy;
Format(std::string("{}")) << 42;
Format(std::string("{}")) << 42;
Format(Format("{{}}")) << 42;
Format(Format("{{}}")) << 42;
\endrst
\endrst
*/
*/
class
StringRef
{
class
StringRef
{
private:
private:
const
char
*
data_
;
const
char
*
data_
;
...
@@ -391,7 +391,7 @@ IntFormatter<int, TypeSpec<'X'> > hexu(int value);
...
@@ -391,7 +391,7 @@ IntFormatter<int, TypeSpec<'X'> > hexu(int value);
**Example**::
**Example**::
std::string s = str(
Basic
Writer() << pad(hex(0xcafe), 8, '0'));
std::string s = str(Writer() << pad(hex(0xcafe), 8, '0'));
// s == "0000cafe"
// s == "0000cafe"
\endrst
\endrst
...
@@ -435,6 +435,11 @@ DEFINE_INT_FORMATTERS(unsigned long)
...
@@ -435,6 +435,11 @@ DEFINE_INT_FORMATTERS(unsigned long)
template
<
typename
Char
>
template
<
typename
Char
>
class
BasicFormatter
;
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
>
template
<
typename
Char
>
class
BasicWriter
{
class
BasicWriter
{
private:
private:
...
@@ -546,9 +551,26 @@ class BasicWriter {
...
@@ -546,9 +551,26 @@ class BasicWriter {
}
}
/**
/**
Formats a string appending the output to the internal buffer.
\rst
Arguments are accepted through the returned `BasicFormatter` object
Formats a string sending the output to the writer. Arguments are
using inserter operator `<<`.
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
);
BasicFormatter
<
Char
>
Format
(
StringRef
format
);
...
@@ -896,27 +918,8 @@ void FormatCustomArg(
...
@@ -896,27 +918,8 @@ void FormatCustomArg(
The :cpp:class:`fmt::BasicFormatter` template provides string formatting
The :cpp:class:`fmt::BasicFormatter` template provides string formatting
functionality similar to Python's `str.format
functionality similar to Python's `str.format
<http://docs.python.org/3/library/stdtypes.html#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 and all
The class provides operator<< for feeding formatting arguments.
the output is sent to a :cpp:class:`fmt::Writer` object.
**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.
\endrst
\endrst
*/
*/
template
<
typename
Char
>
template
<
typename
Char
>
...
@@ -1076,9 +1079,8 @@ class BasicFormatter {
...
@@ -1076,9 +1079,8 @@ class BasicFormatter {
}
}
public
:
public
:
/**
// Constructs a formatter with a writer to be used for output and a format
Constructs a formatter with an empty output buffer.
// format string.
*/
BasicFormatter
(
BasicWriter
<
Char
>
&
w
,
const
Char
*
format
=
0
)
BasicFormatter
(
BasicWriter
<
Char
>
&
w
,
const
Char
*
format
=
0
)
:
writer_
(
&
w
),
format_
(
format
)
{}
:
writer_
(
&
w
),
format_
(
format
)
{}
...
@@ -1086,9 +1088,7 @@ class BasicFormatter {
...
@@ -1086,9 +1088,7 @@ class BasicFormatter {
CompleteFormatting
();
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
)
{}
BasicFormatter
(
const
Proxy
&
p
)
:
BasicFormatter
<
Char
>
(
*
p
.
writer
,
p
.
format
)
{}
operator
Proxy
()
{
operator
Proxy
()
{
...
@@ -1171,16 +1171,30 @@ class NoAction {
...
@@ -1171,16 +1171,30 @@ class NoAction {
};
};
/**
/**
\rst
A formatter with an action performed when formatting is complete.
A formatter with an action performed when formatting is complete.
Objects of this class normally exist only as temporaries returned
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
>
template
<
typename
Action
=
NoAction
,
typename
Char
=
char
>
class
Formatter
:
private
Action
,
public
BasicFormatter
<
Char
>
{
class
Formatter
:
private
Action
,
public
BasicFormatter
<
Char
>
{
private:
friend
class
fmt
::
BasicFormatter
<
Char
>
;
friend
class
fmt
::
StringRef
;
private:
private:
BasicWriter
<
Char
>
writer_
;
BasicWriter
<
Char
>
writer_
;
bool
inactive_
;
bool
inactive_
;
...
@@ -1201,7 +1215,7 @@ class Formatter : private Action, public BasicFormatter<Char> {
...
@@ -1201,7 +1215,7 @@ class Formatter : private Action, public BasicFormatter<Char> {
\rst
\rst
Constructs a formatter with a format string and an action.
Constructs a formatter with a format string and an action.
The action should be an unary function object that takes a const
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
See :cpp:class:`fmt::NoAction` and :cpp:class:`fmt::Write` for
examples of action classes.
examples of action classes.
\endrst
\endrst
...
@@ -1240,13 +1254,17 @@ class Formatter : private Action, public BasicFormatter<Char> {
...
@@ -1240,13 +1254,17 @@ class Formatter : private Action, public BasicFormatter<Char> {
/**
/**
\rst
\rst
Formats a string. Returns a temporary formatter object that accepts
Formats a string similarly to Python's `str.format
arguments via operator ``<<``. *format* is a format string that contains
<http://docs.python.org/3/library/stdtypes.html#str.format>`__.
literal text and replacement fields surrounded by braces ``{}``.
Returns a temporary formatter object that accepts arguments via
The formatter object replaces the fields with formatted arguments
operator ``<<``.
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
*format* is a format string that contains literal text and replacement
accessed as a C string with :cpp:func:`fmt::c_str()`.
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**::
**Example**::
...
@@ -1259,8 +1277,10 @@ inline Formatter<> Format(StringRef format) {
...
@@ -1259,8 +1277,10 @@ inline Formatter<> Format(StringRef format) {
return
Formatter
<>
(
format
);
return
Formatter
<>
(
format
);
}
}
// A formatting action that writes formatted output to stdout.
/** A formatting action that writes formatted output to stdout. */
struct
Write
{
class
Write
{
public:
/** Write the output to stdout. */
void
operator
()(
const
BasicWriter
<
char
>
&
w
)
const
{
void
operator
()(
const
BasicWriter
<
char
>
&
w
)
const
{
std
::
fwrite
(
w
.
data
(),
1
,
w
.
size
(),
stdout
);
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