diff --git a/doc/Text Formatting.html b/doc/Text Formatting.html index 0d0027d4..ae137fa1 100644 --- a/doc/Text Formatting.html +++ b/doc/Text Formatting.html @@ -63,6 +63,7 @@ Victor Zverovich, victor.zverovich@gmail.com Design
    Format String Syntax
    Extensibility
+    Safety
    Locale Support
    Positional Arguments
Wording
@@ -190,12 +191,12 @@ 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. The latter only supports left and right (the default) -alignment. +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. The latter only supports left and +right (the default) alignment.

@@ -215,9 +216,9 @@ The same formatting cannot be easily achieved with printf.

Extensibility

-Both the format string syntax and the 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. +Both the format string syntax and the 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 @@ -234,7 +235,7 @@ functions that do parsing and formatting for such types.

where format-spec is predefined for built-in types, but can be customized for user-defined types. For example, the syntax can be extended -for put_time-like date and time formatting: +for put_time-like date and time formatting

@@ -242,16 +243,51 @@ for put_time-like date and time formatting:
 std::string date = std::format("The date is {0:%Y-%m-%d}.", *std::localtime(&t));
 
-

TODO: API

+

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

+ +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

-

TODO

+

+As pointed out in + +P0067R1: Elementary string conversions there is a number of use +cases that do not require internationalization support, but do require high +throughput when produced by a server. These include various text-based +interchange formats such as JSON or XML. The need for locale-independent +functions for conversions between integers and strings and between +floating-point numbers and strings has also been highlighted in + +N4412: Shortcomings of iostreams. Therefore a user should be able to +easily control whether to use locales or not during formatting. +

+ +

+We follow Python's approach [3] and designate a separate format +specifier 'n' for locale-aware numeric formatting. It applies to +all integral and floating-point types. All other specifiers produce output +unaffected by locale settings. +

Positional Arguments

TODO

+

Performance

+ +

TODO

+

Wording

TODO

@@ -260,7 +296,7 @@ std::string date = std::format("The date is {0:%Y-%m-%d}.", *std::localtime(&t))

The ideas proposed in this paper have been implemented in the open-source fmt -library. TODO: link +library. TODO: link and mention other implementations (Boost Format, FastFormat)

References