diff --git a/doc/Text Formatting.html b/doc/Text Formatting.html
index fda0c067..4ad2700c 100644
--- a/doc/Text Formatting.html
+++ b/doc/Text Formatting.html
@@ -66,6 +66,7 @@ Victor Zverovich, victor.zverovich@gmail.com
Safety
Locale Support
Positional Arguments
+ Performance
Binary Footprint
Proposed Wording
References
@@ -124,7 +125,8 @@ 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
'}'
as replacement field delimiters instead of '%'
-and it is described in details in TODO:link. Here are some of the advantages:
+and it is described in details in the syntax reference.
+Here are some of the advantages:
-printf("String `%s' has %d characters\n", string, length(string)))
+printf("String `%s' has %d characters\n", string, length(string)));
A possible German translation of the format string might be:
@@ -299,12 +301,12 @@ arguments because the word order may vary in different languagesusing POSIX positional arguments [2]. Unfortunately these positional specifiers are not portable [6]. The C++ I/O -streams don't support positional arguments by design because formatting -arguments are interleaved with the portions of the literal string: +streams don't support such rearranging of arguments by design because they +are interleaved with the portions of the literal string:
-std::cout << "String `" << string << "' has " << length(string) << " characters\n"
+std::cout << "String `" << string << "' has " << length(string) << " characters\n";
@@ -313,7 +315,7 @@ arguments, for example:
-std::format("String `{}' has {} characters\n", string, length(string)))
+std::format("String `{}' has {} characters\n", string, length(string)));
with the German translation of the format string:
@@ -342,23 +344,33 @@ TODO: rephrase and mention format_args
namespace std {
+ class format_error;
+
class format_args;
template <class Char>
- basic_string<Char> format(const Char *fmt, format_args args);
+ 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);
+ basic_string<Char> format(const Char* fmt, const Args&... args);
}
-
+Format strings contain replacement fields surrounded by curly braces
+{}
. Anything that is not contained in braces is considered literal
+text, which is copied unchanged to the output. A brace character can be
+included in the literal text by doubling: {{
and }}
.
+The syntax for replacement fields is as follows:
+
replacement-field ::= '{' [arg-id] [':' format-spec] '}'
arg-id ::= integer
integer ::= digit+
-digit ::= '0'...'9'
+digit ::= '0'...'9'
@@ -373,6 +385,61 @@ type ::= int-type | 'a' | 'A' | 'c' | 'e' | 'E' | 'f' | 'F' | 'g' | 'G'
int-type ::= 'b' | 'B' | 'd' | 'o' | 'x' | 'X'
+format_error
+class format_error : public std::runtime_error {
+public:
+ explicit format_error(const string& what_arg);
+ explicit format_error(const char* what_arg);
+};
+
+
+
+The class format_error
defines the type of objects thrown as
+exceptions to report errors from the formatting library.
+
format_error(const string& what_arg);
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
.
format
+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);
+
+Requires: fmt
shall not be a null pointer.
+Effects: Each function returns a basic_string
object
+constructed from the format string argument fmt
with each
+replacement field substituted with the character representation of the
+argument it refers to, formatted according to the specification given in the
+field.
+
Returns: The formatted string.
+Throws: format_error
if fmt
is not a valid
+format string.