From 8e7441c27485bd416abdb0253c9c92620d671065 Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Tue, 6 May 2014 10:34:07 +0200 Subject: Make the scanned form of the io_lib format strings available for processing This adds three new functions to io_lib - scan_format/2, unscan_format/1, and build_text/1 - which expose the parsed form of the format control sequences to make it possible to easily modify or filter the input to io_lib:format/2. This can e.g. be used in order to replace unbounded-size control sequences like ~w or ~p with corresponding depth-limited ~W and ~P before doing the actual formatting. --- lib/stdlib/doc/src/io.xml | 3 +- lib/stdlib/doc/src/io_lib.xml | 70 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) (limited to 'lib/stdlib/doc') diff --git a/lib/stdlib/doc/src/io.xml b/lib/stdlib/doc/src/io.xml index a28180b42a..8ebfdb2e7f 100644 --- a/lib/stdlib/doc/src/io.xml +++ b/lib/stdlib/doc/src/io.xml @@ -505,7 +505,8 @@ ok

Writes the data with standard syntax in the same way as ~w, but breaks terms whose printed representation is longer than one line into many lines and indents each - line sensibly. It also tries to detect lists of + line sensibly. Left justification is not supported. + It also tries to detect lists of printable characters and to output these as strings. The Unicode translation modifier is used for determining what characters are printable. For example:

diff --git a/lib/stdlib/doc/src/io_lib.xml b/lib/stdlib/doc/src/io_lib.xml index 3312b08064..2117d66381 100644 --- a/lib/stdlib/doc/src/io_lib.xml +++ b/lib/stdlib/doc/src/io_lib.xml @@ -4,7 +4,7 @@
- 19962013 + 19962014 Ericsson AB. All Rights Reserved. @@ -59,6 +59,35 @@ + + +

Description:

+ +

control_char is the type of control + sequence: $P, $w, and so on;

+
+

args is a list of the arguments used by the + control sequence, or an empty list if the control sequence + does not take any arguments;

+
+

width is the field width;

+
+

adjust is the adjustment;

+
+

precision is the precision of the printed + argument;

+
+

pad_char is the padding character;

+
+

encoding is set to true if the translation + modifier t is present;

+
+

strings is set to false if the modifier + l is present.

+
+
+
+
@@ -259,6 +288,45 @@ constant in the ISO-latin-1 character set.

+ + + Parse all control sequences in the format string + +

Returns a list corresponding to the given format string, + where control sequences have been replaced with + corresponding tuples. This list can be passed to io_lib:build_text/1 to have + the same effect as io_lib:format(Format, Args), or to + io_lib:unscan_format/1 + in order to get the corresponding pair of Format and + Args (with every * and corresponding argument + expanded to numeric values).

+

A typical use of this function is to replace unbounded-size + control sequences like ~w and ~p with the + depth-limited variants ~W and ~P before + formatting to text, e.g. in a logger.

+
+
+ + + Revert a pre-parsed format list to a plain character list + and a list of arguments + +

See io_lib:scan_format/2 for + details.

+
+
+ + + Build the output text for a pre-parsed format list + +

See io_lib:scan_format/2 for + details.

+
+
Indentation after printing string -- cgit v1.2.3