diff --git a/doc/Text Formatting.html b/doc/Text Formatting.html index e066313e..e8feaa88 100644 --- a/doc/Text Formatting.html +++ b/doc/Text Formatting.html @@ -4,6 +4,48 @@
Example: -
-std::string message = std::format("The answer is {}.", 42)++std::string message = std::format("The answer is {}.", 42);Design
@@ -62,7 +105,7 @@ of issues:
'%' in a custom format specifier, e.g. for
put_time-like time formatting, poses difficulties.
The syntax is expressive enough to enable translation, possibly automated,
-of most printf format strings. TODO: table of correspondence between
-printf and the new syntax
+of most printf format strings. The correspondence between printf
+and the new syntax is given in the following table.
| printf | new | comment |
|---|---|---|
| - | < | left alignment |
| + | + | |
| space | space | |
| hh | unused | |
| h | unused | |
| l | unused | |
| ll | unused | |
| j | unused | |
| z | unused | |
| t | unused | |
| L | unused | |
| c | c (optional) | |
| s | s (optional) | |
| d | d (optional) | |
| i | d (optional) | |
| o | o | |
| x | x | |
| X | X | |
| u | d (optional) | |
| f | f | |
| F | F | |
| e | e | |
| E | E | |
| a | a | |
| A | A | |
| g | g (optional) | |
| G | G | |
| n | unused | |
| p | p (optional) |
+Width and precision are represented similarly in printf and the
+proposed syntax with the only difference that runtime value is specified by
+* in the former and {} in the latter, possibly with
+the index of the argument inside the braces.
+
+As can be seen from the table above, most of the specifiers remain the same
+which simplifies migration from printf. Notable difference is in
+the alignment specification. The proposed syntax allows left, center, and right
+alignment represented by '<', '^', and
+'>' respectively which is more expressive than the corresponding
+printf syntax.
+
+Both format string syntax and API are designed with extensibility in mind. +The mini-language can be extended for user-defined types and users can provide +functions that do parsing and formatting for such types. +
+ +The general syntax of a replacement field in a format string is + +
{ integeropt }{ integeropt
+ : format-spec }
++where format-spec is predefined for built-in types, but can be +customized for user-defined types. For example, time formatting + +TODO: elaborate
+TODO
@@ -106,8 +227,6 @@ printf and the new syntaxTODO
-@@ -115,6 +234,8 @@ The ideas proposed in this paper have been implemented in the open-source fmt library. TODO: link
+
[1]
The fprintf function. ISO/IEC 9899:2011. 7.21.6.1.
@@ -131,6 +252,10 @@ String.Format Method. .NET Framework Class Library.
[5]
Module std::fmt. The Rust Standard Library.
+[6]
+
+Format Specification Syntax: printf and wprintf Functions. C++ Language and
+Standard Libraries.