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
d775a20f
Commit
d775a20f
authored
Aug 24, 2016
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update paper
parent
4dc9fd99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
19 deletions
+61
-19
doc/Text Formatting.html
doc/Text Formatting.html
+61
-19
No files found.
doc/Text Formatting.html
View file @
d775a20f
...
...
@@ -167,7 +167,7 @@ and can potentially be more confusing to users than introducing a different
syntax.
</p>
<
/
p>
<p>
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>
,
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"
>
<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(
&
amp;
t));
</code>
</pre>
<p>
by providing an overload of
<code>
std::format_arg
</code>
for
<code>
std::tm
</code>
:
</p>
TODO: example
<p>
TODO: example
</p>
<h3><a
name=
"Safety"
>
Safety
</a></h3>
<p>
Formatting functions rely on variadic templates instead of the mechanism
provided by
<code>
<
cstdarg
>
</code>
. The type information is captured
automatically and passed to formatters guaranteeing type safety and making
many of the
<code>
printf
</code>
specifiers redundant (see
<a
href=
"#Syntax"
>
Format String Syntax
</a>
). Buffer management is also automatic to prevent
buffer overflow errors common to
<code>
printf
</code>
.
</p>
<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>
</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>
...
...
@@ -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>
Postcondition
</i>
:
<code>
strcmp(what(), what_arg.c_str()) == 0
</code>
.
</p>
</dd>
<dt><code>
format_error(const char* what_arg);
</code></dt>
<dd>
<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>
</dd>
</dl>
<h3>
Class
<code>
format_args
</code></h3>
...
...
@@ -536,13 +579,11 @@ exceptions to report errors from the formatting library.
<dl>
<dt>
<pre>
<code>
template
<
class Char
>
basic_string
<
Char
>
format(const Char* fmt, format_args args);
template
<
class Char, class ...Args
>
basic_string
<
Char
>
format(const Char* fmt, const Args
&
... args);
</code>
</pre>
<code>
template
<
class Char
>
<br>
basic_string
<
Char
>
format(const Char* fmt, format_args args);
<br>
<br>
template
<
class Char, class ...Args
>
<br>
basic_string
<
Char
>
format(const Char* fmt, const Args
&
... args);
</code>
</dt>
<dd>
...
...
@@ -558,6 +599,7 @@ field.
<p><i>
Throws
</i>
:
<code>
format_error
</code>
if
<code>
fmt
</code>
is not a valid
format string.
</p>
</dd>
</dl>
<h2><a
name=
"Implementation"
>
Implementation
</a></h2>
...
...
@@ -570,27 +612,27 @@ library. TODO: link and mention other implementations (Boost Format, FastFormat)
<p>
<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>
<cite><a
href=
"http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html"
>
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>
<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>
<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>
<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>
<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
Standard Libraries.
</cite><br
/
>
Standard Libraries.
</cite><br>
<a
name=
"7"
>
[7]
</a>
<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>
</body>
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