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
1e724a9d
Commit
1e724a9d
authored
Sep 08, 2013
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write docs.
parent
06dda99d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
37 deletions
+71
-37
doc/index.rst
doc/index.rst
+5
-5
format.h
format.h
+66
-32
No files found.
doc/index.rst
View file @
1e724a9d
...
...
@@ -19,7 +19,7 @@ String Formatting API
.. doxygenclass:: fmt::Write
:members:
.. doxygenclass:: fmt::StringRef
.. doxygenclass:: fmt::
Basic
StringRef
:members:
.. doxygenfunction:: fmt::str
...
...
@@ -190,8 +190,8 @@ sign-aware zero-padding for numeric types. This is equivalent to a *fill*
character of ``'0'`` with an *alignment* type of ``'='``.
The *precision* is a decimal number indicating how many digits should be
displayed after the decimal point for a floating
point value formatted with
``'f'`` and ``'F'``, or before and after the decimal point for a floating
point
displayed after the decimal point for a floating
-
point value formatted with
``'f'`` and ``'F'``, or before and after the decimal point for a floating
-
point
value formatted with ``'g'`` or ``'G'``. For non-number types the field
indicates the maximum field size - in other words, how many characters will be
used from the field content. The *precision* is not allowed for integer values.
...
...
@@ -225,7 +225,7 @@ The available integer presentation types are:
+---------+----------------------------------------------------------+
| Type | Meaning |
+=========+==========================================================+
| ``'d'`` | Decimal
I
nteger. Outputs the number in base 10. |
| ``'d'`` | Decimal
i
nteger. Outputs the number in base 10. |
+---------+----------------------------------------------------------+
| ``'o'`` | Octal format. Outputs the number in base 8. |
+---------+----------------------------------------------------------+
...
...
@@ -238,7 +238,7 @@ The available integer presentation types are:
| none | The same as ``'d'``. |
+---------+----------------------------------------------------------+
The available presentation types for floating
point values are:
The available presentation types for floating
-
point values are:
+---------+----------------------------------------------------------+
| Type | Meaning |
...
...
format.h
View file @
1e724a9d
...
...
@@ -214,7 +214,7 @@ class BasicStringRef {
public:
/**
Constructs a string reference object from a C string and a size.
If
`size`
is zero, which is the default, the size is computed with
If
*size*
is zero, which is the default, the size is computed with
`strlen`.
*/
BasicStringRef
(
const
Char
*
s
,
std
::
size_t
size
=
0
)
:
data_
(
s
),
size_
(
size
)
{}
...
...
@@ -406,9 +406,37 @@ template <typename Char>
class
BasicFormatter
;
/**
\rst
This template provides operations for formatting and writing data into
a character stream. The output is stored in a memory buffer that grows
dynamically.
You can use one of the following typedefs for common character types:
+---------+----------------------+
| Type | Definition |
+=========+======================+
| Writer | BasicWriter<char> |
+---------+----------------------+
| WWriter | BasicWriter<wchar_t> |
+---------+----------------------+
**Example**::
Writer out;
out << "The answer is " << 42 << "\n";
out.Format("({:+f}, {:+f})") << -3.14 << 3.14;
This will write the following output to the ``out`` object:
.. code-block:: none
The answer is 42
(-3.140000, +3.140000)
The output can be converted to an ``std::string`` with ``out.str()`` or
accessed as a C string with ``out.c_str()``.
\endrst
*/
template
<
typename
Char
>
class
BasicWriter
{
...
...
@@ -454,7 +482,7 @@ class BasicWriter {
*
this
<<
IntFormatter
<
T
,
FormatSpec
>
(
value
,
spec
);
}
// Formats a floating
point number (double or long double).
// Formats a floating
-
point number (double or long double).
template
<
typename
T
>
void
FormatDouble
(
T
value
,
const
FormatSpec
&
spec
,
int
precision
);
...
...
@@ -492,6 +520,32 @@ class BasicWriter {
return
std
::
basic_string
<
Char
>
(
&
buffer_
[
0
],
buffer_
.
size
());
}
/**
\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`.
See also `Format String Syntax`_.
\endrst
*/
BasicFormatter
<
Char
>
Format
(
StringRef
format
);
BasicWriter
&
operator
<<
(
int
value
)
{
return
*
this
<<
IntFormatter
<
int
,
TypeSpec
<
0
>
>
(
value
,
TypeSpec
<
0
>
());
}
...
...
@@ -502,11 +556,19 @@ class BasicWriter {
BasicWriter
&
operator
<<
(
long
value
)
{
return
*
this
<<
IntFormatter
<
long
,
TypeSpec
<
0
>
>
(
value
,
TypeSpec
<
0
>
());
}
/**
Formats *value* and writes it to the stream.
*/
BasicWriter
&
operator
<<
(
unsigned
long
value
)
{
return
*
this
<<
IntFormatter
<
unsigned
long
,
TypeSpec
<
0
>
>
(
value
,
TypeSpec
<
0
>
());
}
/**
Formats *value* using the general format for floating-point numbers
(``'g'``) and writes it to the stream.
*/
BasicWriter
&
operator
<<
(
double
value
)
{
FormatDouble
(
value
,
FormatSpec
(),
-
1
);
return
*
this
;
...
...
@@ -530,30 +592,6 @@ class BasicWriter {
FormatString
(
s
.
data
(),
s
.
size
(),
spec
);
}
/**
\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
);
void
Clear
()
{
buffer_
.
clear
();
}
...
...
@@ -990,9 +1028,7 @@ class Formatter : private Action, public BasicFormatter<Char> {
inactive_
(
false
)
{
}
/**
Constructs a formatter from a proxy object.
*/
// Constructs a formatter from a proxy object.
Formatter
(
const
Proxy
&
p
)
:
Action
(
p
.
action
),
BasicFormatter
<
Char
>
(
writer_
,
p
.
format
),
inactive_
(
false
)
{
...
...
@@ -1008,9 +1044,7 @@ class Formatter : private Action, public BasicFormatter<Char> {
}
}
/**
Converts the formatter into a proxy object.
*/
// Converts the formatter into a proxy object.
operator
Proxy
()
{
inactive_
=
true
;
return
Proxy
(
this
->
TakeFormatString
(),
*
this
);
...
...
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