From d775a20fff0be6e087dd3a160e1b662606b9247e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 24 Aug 2016 07:41:07 -0700 Subject: [PATCH] Update paper --- doc/Text Formatting.html | 80 ++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/doc/Text Formatting.html b/doc/Text Formatting.html index 214cf7aa..bc5fa47c 100644 --- a/doc/Text Formatting.html +++ b/doc/Text Formatting.html @@ -167,7 +167,7 @@ and can potentially be more confusing to users than introducing a different syntax.

-

+

Therefore we propose a new syntax based on the ones used in Python [3], the .NET family of languages [4], and Rust [5]. This syntax employs '{' and @@ -286,22 +286,24 @@ for put_time-like date and time formatting

 std::time_t t = std::time(nullptr);
-std::string date = std::format("The date is {0:%Y-%m-%d}.", *std::localtime(&t));
+std::string date = std::format("The date is {0:%Y-%m-%d}.", *std::localtime(&t));
 

by providing an overload of std::format_arg for std::tm:

-TODO: example +

TODO: example

Safety

+

Formatting functions rely on variadic templates instead of the mechanism provided by <cstdarg>. The type information is captured automatically and passed to formatters guaranteeing type safety and making many of the printf specifiers redundant (see Format String Syntax). Buffer management is also automatic to prevent buffer overflow errors common to printf. +

Locale Support

@@ -498,7 +500,48 @@ type ::= int-type | 'a' | 'A' | 'c' | 'e' | 'E' | 'f' | 'F' | 'g' | 'G' int-type ::= 'b' | 'B' | 'd' | 'o' | 'x' | 'X' -TODO +

+The fill character can be any character other than '{' +or '}'. 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 format-spec is not a valid alignment option, +then it is assumed that both the fill character and the alignment option are +absent. + +

+The meaning of the various alignment options is as follows: +

+ + + + + + + + + + + + + + + + + + + + + + + +
OptionMeaning
'<'Forces the field to be left-aligned within the available space (this is + the default for most objects).
'>'Forces the field to be right-aligned within the available space (this is + the default for numbers).
'='Forces the padding to be placed after the sign (if any) but before the + digits. This is used for printing fields in the form + +000000120. This alignment option is only valid for numeric + types.
'^'Forces the field to be centered within the available space.
+ +

TODO

Class format_error

@@ -521,12 +564,12 @@ exceptions to report errors from the formatting library.

Effects: Constructs an object of class format_error.

Postcondition: strcmp(what(), what_arg.c_str()) == 0.

-
format_error(const char* what_arg);

Effects: Constructs an object of class format_error.

Postcondition: strcmp(what(), what_arg) == 0.

+

Class format_args

@@ -536,13 +579,11 @@ exceptions to report errors from the formatting library.
-
-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);
-
+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);
@@ -558,6 +599,7 @@ field.

Throws: format_error if fmt is not a valid format string.

+

Implementation

@@ -570,27 +612,27 @@ library. TODO: link and mention other implementations (Boost Format, FastFormat)

[1] -The fprintf function. ISO/IEC 9899:2011. 7.21.6.1.
+The fprintf function. ISO/IEC 9899:2011. 7.21.6.1.
[2] fprintf, printf, snprintf, sprintf - print formatted output. The Open -Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition.
+Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition.
[3] -6.1.3. Format String Syntax. Python 3.5.2 documentation.
+6.1.3. Format String Syntax. Python 3.5.2 documentation.
[4] -String.Format Method. .NET Framework Class Library.
+String.Format Method. .NET Framework Class Library.
[5] -Module std::fmt. The Rust Standard Library.
+Module std::fmt. The Rust Standard Library.
[6] Format Specification Syntax: printf and wprintf Functions. C++ Language and -Standard Libraries.
+Standard Libraries.
[7] -10.4.2 Rearranging printf Arguments. The GNU Awk User's Guide.
+10.4.2 Rearranging printf Arguments. The GNU Awk User's Guide.