mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-07 13:20:05 +00:00
Update paper
This commit is contained in:
parent
4dc9fd995f
commit
d775a20fff
@ -167,7 +167,7 @@ and can potentially be more confusing to users than introducing a different
|
|||||||
syntax.
|
syntax.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</p>
|
<p>
|
||||||
Therefore we propose a new syntax based on the ones used in Python
|
Therefore we propose a new syntax based on the ones used in Python
|
||||||
<a href="#3">[3]</a>, the .NET family of languages <a href="#4">[4]</a>,
|
<a href="#3">[3]</a>, the .NET family of languages <a href="#4">[4]</a>,
|
||||||
and Rust <a href="#5">[5]</a>. This syntax employs <code>'{'</code> and
|
and Rust <a href="#5">[5]</a>. This syntax employs <code>'{'</code> and
|
||||||
@ -286,22 +286,24 @@ for <code>put_time</code>-like date and time formatting
|
|||||||
|
|
||||||
<pre class="example">
|
<pre class="example">
|
||||||
<code>std::time_t t = std::time(nullptr);
|
<code>std::time_t t = std::time(nullptr);
|
||||||
std::string date = std::format("The date is {0:%Y-%m-%d}.", *std::localtime(&t));</code>
|
std::string date = std::format("The date is {0:%Y-%m-%d}.", *std::localtime(&t));</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>by providing an overload of <code>std::format_arg</code> for
|
<p>by providing an overload of <code>std::format_arg</code> for
|
||||||
<code>std::tm</code>:</p>
|
<code>std::tm</code>:</p>
|
||||||
|
|
||||||
TODO: example
|
<p>TODO: example</p>
|
||||||
|
|
||||||
<h3><a name="Safety">Safety</a></h3>
|
<h3><a name="Safety">Safety</a></h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
Formatting functions rely on variadic templates instead of the mechanism
|
Formatting functions rely on variadic templates instead of the mechanism
|
||||||
provided by <code><cstdarg></code>. The type information is captured
|
provided by <code><cstdarg></code>. The type information is captured
|
||||||
automatically and passed to formatters guaranteeing type safety and making
|
automatically and passed to formatters guaranteeing type safety and making
|
||||||
many of the <code>printf</code> specifiers redundant (see <a href="#Syntax">
|
many of the <code>printf</code> specifiers redundant (see <a href="#Syntax">
|
||||||
Format String Syntax</a>). Buffer management is also automatic to prevent
|
Format String Syntax</a>). Buffer management is also automatic to prevent
|
||||||
buffer overflow errors common to <code>printf</code>.
|
buffer overflow errors common to <code>printf</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
<h3><a name="Locale">Locale Support</a></h3>
|
<h3><a name="Locale">Locale Support</a></h3>
|
||||||
|
|
||||||
@ -498,7 +500,48 @@ type ::= int-type | 'a' | 'A' | 'c' | 'e' | 'E' | 'f' | 'F' | 'g' | 'G'
|
|||||||
int-type ::= 'b' | 'B' | 'd' | 'o' | 'x' | 'X'</code>
|
int-type ::= 'b' | 'B' | 'd' | 'o' | 'x' | 'X'</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
TODO
|
<p>
|
||||||
|
The <code>fill</code> character can be any character other than <code>'{'</code>
|
||||||
|
or <code>'}'</code>. The presence of a fill character is signaled by the
|
||||||
|
character following it, which must be one of the alignment options. If the
|
||||||
|
second character of <code>format-spec</code> is not a valid alignment option,
|
||||||
|
then it is assumed that both the fill character and the alignment option are
|
||||||
|
absent.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The meaning of the various alignment options is as follows:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr><th>Option</th><th>Meaning</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>'<'</td>
|
||||||
|
<td>Forces the field to be left-aligned within the available space (this is
|
||||||
|
the default for most objects).</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>'>'</td>
|
||||||
|
<td>Forces the field to be right-aligned within the available space (this is
|
||||||
|
the default for numbers).</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>'='</td>
|
||||||
|
<td>Forces the padding to be placed after the sign (if any) but before the
|
||||||
|
digits. This is used for printing fields in the form
|
||||||
|
<code>+000000120</code>. This alignment option is only valid for numeric
|
||||||
|
types.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>'^'</td>
|
||||||
|
<td>Forces the field to be centered within the available space.</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>TODO</p>
|
||||||
|
|
||||||
<h3>Class <code>format_error</code></h3>
|
<h3>Class <code>format_error</code></h3>
|
||||||
|
|
||||||
@ -521,12 +564,12 @@ exceptions to report errors from the formatting library.
|
|||||||
<p><i>Effects</i>: Constructs an object of class <code>format_error</code>.</p>
|
<p><i>Effects</i>: Constructs an object of class <code>format_error</code>.</p>
|
||||||
<p><i>Postcondition</i>: <code>strcmp(what(), what_arg.c_str()) == 0</code>.</p>
|
<p><i>Postcondition</i>: <code>strcmp(what(), what_arg.c_str()) == 0</code>.</p>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt><code>format_error(const char* what_arg);</code></dt>
|
<dt><code>format_error(const char* what_arg);</code></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<p><i>Effects</i>: Constructs an object of class <code>format_error</code>.</p>
|
<p><i>Effects</i>: Constructs an object of class <code>format_error</code>.</p>
|
||||||
<p><i>Postcondition</i>: <code>strcmp(what(), what_arg) == 0</code>.</p>
|
<p><i>Postcondition</i>: <code>strcmp(what(), what_arg) == 0</code>.</p>
|
||||||
</dd>
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
<h3>Class <code>format_args</code></h3>
|
<h3>Class <code>format_args</code></h3>
|
||||||
|
|
||||||
@ -536,13 +579,11 @@ exceptions to report errors from the formatting library.
|
|||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
<pre>
|
<code>template <class Char><br>
|
||||||
<code>template <class Char>
|
basic_string<Char> format(const Char* fmt, format_args args);<br>
|
||||||
basic_string<Char> format(const Char* fmt, format_args args);
|
<br>
|
||||||
|
template <class Char, class ...Args><br>
|
||||||
template <class Char, class ...Args>
|
basic_string<Char> format(const Char* fmt, const Args&... args);</code>
|
||||||
basic_string<Char> format(const Char* fmt, const Args&... args);</code>
|
|
||||||
</pre>
|
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
|
|
||||||
@ -558,6 +599,7 @@ field.
|
|||||||
<p><i>Throws</i>: <code>format_error</code> if <code>fmt</code> is not a valid
|
<p><i>Throws</i>: <code>format_error</code> if <code>fmt</code> is not a valid
|
||||||
format string.</p>
|
format string.</p>
|
||||||
</dd>
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
<h2><a name="Implementation">Implementation</a></h2>
|
<h2><a name="Implementation">Implementation</a></h2>
|
||||||
|
|
||||||
@ -570,27 +612,27 @@ library. TODO: link and mention other implementations (Boost Format, FastFormat)
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a name="1">[1]</a>
|
<a name="1">[1]</a>
|
||||||
<cite>The <code>fprintf</code> function. ISO/IEC 9899:2011. 7.21.6.1.</cite><br/>
|
<cite>The <code>fprintf</code> function. ISO/IEC 9899:2011. 7.21.6.1.</cite><br>
|
||||||
<a name="2">[2]</a>
|
<a name="2">[2]</a>
|
||||||
<cite><a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html">
|
<cite><a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html">
|
||||||
fprintf, printf, snprintf, sprintf - print formatted output</a>. The Open
|
fprintf, printf, snprintf, sprintf - print formatted output</a>. The Open
|
||||||
Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition.</cite><br/>
|
Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition.</cite><br>
|
||||||
<a name="3">[3]</a>
|
<a name="3">[3]</a>
|
||||||
<cite><a href="https://docs.python.org/3/library/string.html#format-string-syntax">
|
<cite><a href="https://docs.python.org/3/library/string.html#format-string-syntax">
|
||||||
6.1.3. Format String Syntax</a>. Python 3.5.2 documentation.</cite><br/>
|
6.1.3. Format String Syntax</a>. Python 3.5.2 documentation.</cite><br>
|
||||||
<a name="4">[4]</a>
|
<a name="4">[4]</a>
|
||||||
<cite><a href="https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx">
|
<cite><a href="https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx">
|
||||||
String.Format Method</a>. .NET Framework Class Library.</cite><br/>
|
String.Format Method</a>. .NET Framework Class Library.</cite><br>
|
||||||
<a name="5">[5]</a>
|
<a name="5">[5]</a>
|
||||||
<cite><a href="https://doc.rust-lang.org/std/fmt/">
|
<cite><a href="https://doc.rust-lang.org/std/fmt/">
|
||||||
Module <code>std::fmt</code></a>. The Rust Standard Library.</cite><br/>
|
Module <code>std::fmt</code></a>. The Rust Standard Library.</cite><br>
|
||||||
<a name="6">[6]</a>
|
<a name="6">[6]</a>
|
||||||
<cite><a href="https://msdn.microsoft.com/en-us/library/56e442dc(v=vs.120).aspx">
|
<cite><a href="https://msdn.microsoft.com/en-us/library/56e442dc(v=vs.120).aspx">
|
||||||
Format Specification Syntax: printf and wprintf Functions</a>. C++ Language and
|
Format Specification Syntax: printf and wprintf Functions</a>. C++ Language and
|
||||||
Standard Libraries.</cite><br/>
|
Standard Libraries.</cite><br>
|
||||||
<a name="7">[7]</a>
|
<a name="7">[7]</a>
|
||||||
<cite><a href="ftp://ftp.gnu.org/old-gnu/Manuals/gawk-3.1.0/html_chapter/gawk_11.html">
|
<cite><a href="ftp://ftp.gnu.org/old-gnu/Manuals/gawk-3.1.0/html_chapter/gawk_11.html">
|
||||||
10.4.2 Rearranging printf Arguments</a>. The GNU Awk User's Guide.</cite><br/>
|
10.4.2 Rearranging printf Arguments</a>. The GNU Awk User's Guide.</cite><br>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user