From 675b8108486919739dc2e213587489c0daab80cb Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Sun, 13 Jan 2013 18:19:29 +0100 Subject: [stdlib] Add control sequence modifier 'l' The modifier 'l' can be used for turning off the string recognition of ~p and ~P. --- lib/stdlib/doc/src/io.xml | 67 ++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/io.xml b/lib/stdlib/doc/src/io.xml index fa475804eb..9f59fda6b5 100644 --- a/lib/stdlib/doc/src/io.xml +++ b/lib/stdlib/doc/src/io.xml @@ -390,10 +390,11 @@ ok applicable, it is used for both the field width and precision. The default padding character is ' ' (space).

Mod is the control sequence modifier. It is either a - single character (currently only t, for Unicode translation, - is supported) that changes the interpretation of Data.

- -

The following control sequences are available:

+ single character (currently only t, for Unicode + translation, and l, for stopping p and + P from detecting printable characters, are supported) + that changes the interpretation of Data.

+

The following control sequences are available:

~ @@ -407,7 +408,7 @@ ok which in turn defaults to 1. The following example illustrates:

-2> io:fwrite("|~10.5c|~-10.5c|~5c|~n", [$a, $b, $c]).
+1> io:fwrite("|~10.5c|~-10.5c|~5c|~n", [$a, $b, $c]).
 |     aaaaa|bbbbb     |ccccc|
 ok

If the Unicode translation modifier (t) is in effect, @@ -415,10 +416,10 @@ ok valid Unicode codepoint, otherwise it should be an integer less than or equal to 255, otherwise it is masked with 16#FF:

-1> io:fwrite("~tc~n",[1024]).
+2> io:fwrite("~tc~n",[1024]).
 \x{400}
 ok
-2> io:fwrite("~c~n",[1024]).
+3> io:fwrite("~c~n",[1024]).
 ^@
 ok
@@ -462,20 +463,20 @@ ok

This format can be used for printing any object and truncating the output so it fits a specified field:

-3> io:fwrite("|~10w|~n", [{hey, hey, hey}]).
+1> io:fwrite("|~10w|~n", [{hey, hey, hey}]).
 |**********|
 ok
-4> io:fwrite("|~10s|~n", [io_lib:write({hey, hey, hey})]).
+2> io:fwrite("|~10s|~n", [io_lib:write({hey, hey, hey})]).
 |{hey,hey,h|
-5> io:fwrite("|~-10.8s|~n", [io_lib:write({hey, hey, hey})]).
+3> io:fwrite("|~-10.8s|~n", [io_lib:write({hey, hey, hey})]).
 |{hey,hey  |
 ok

A list with integers larger than 255 is considered an error if the Unicode translation modifier is not given:

-1> io:fwrite("~ts~n",[[1024]]).
+4> io:fwrite("~ts~n",[[1024]]).
 \x{400}
 ok
-2> io:fwrite("~s~n",[[1024]]).
+5> io:fwrite("~s~n",[[1024]]).
 ** exception exit: {badarg,[{io,format,[<0.26.0>,"~s~n",[[1024]]]},
    ...
@@ -496,17 +497,17 @@ ok printable characters and to output these as strings. For example:

-5> T = [{attributes,[[{id,age,1.50000},{mode,explicit},
+1> T = [{attributes,[[{id,age,1.50000},{mode,explicit},
 {typename,"INTEGER"}], [{id,cho},{mode,explicit},{typename,'Cho'}]]},
 {typename,'Person'},{tag,{'PRIVATE',3}},{mode,implicit}].
 ...
-6> io:fwrite("~w~n", [T]).
+2> io:fwrite("~w~n", [T]).
 [{attributes,[[{id,age,1.5},{mode,explicit},{typename,
 [73,78,84,69,71,69,82]}],[{id,cho},{mode,explicit},{typena
 me,'Cho'}]]},{typename,'Person'},{tag,{'PRIVATE',3}},{mode
 ,implicit}]
 ok
-7> io:fwrite("~62p~n", [T]).
+3> io:fwrite("~62p~n", [T]).
 [{attributes,[[{id,age,1.5},
                {mode,explicit},
                {typename,"INTEGER"}],
@@ -522,7 +523,7 @@ ok
io:fwrite or io:format. For example, using T above:

-8> io:fwrite("Here T = ~62p~n", [T]).
+4> io:fwrite("Here T = ~62p~n", [T]).
 Here T = [{attributes,[[{id,age,1.5},
                         {mode,explicit},
                         {typename,"INTEGER"}],
@@ -532,6 +533,18 @@ Here T = [{attributes,[[{id,age,1.5},
           {typename,'Person'},
           {tag,{'PRIVATE',3}},
           {mode,implicit}]
+ok
+

When the modifier l is given no detection of + printable character lists will take place. For example:

+
+5> S = [{a,"a"}, {b, "b"}].
+6> io:fwrite("~15p~n", [S]).
+[{a,"a"},
+ {b,"b"}]
+ok
+7> io:fwrite("~15lp~n", [S]).
+[{a,[97]},
+ {b,[98]}]
 ok
W @@ -541,7 +554,7 @@ ok are printed. Anything below this depth is replaced with .... For example, using T above:

-9> io:fwrite("~W~n", [T,9]).
+8> io:fwrite("~W~n", [T,9]).
 [{attributes,[[{id,age,1.5},{mode,explicit},{typename,...}],
 [{id,cho},{mode,...},{...}]]},{typename,'Person'},
 {tag,{'PRIVATE',3}},{mode,implicit}]
@@ -558,7 +571,7 @@ ok
are printed. Anything below this depth is replaced with .... For example:

-10> io:fwrite("~62P~n", [T,9]).
+9> io:fwrite("~62P~n", [T,9]).
 [{attributes,[[{id,age,1.5},{mode,explicit},{typename,...}],
               [{id,cho},{mode,...},{...}]]},
  {typename,'Person'},
@@ -572,13 +585,13 @@ ok
10. A leading dash is printed for negative integers.

The precision field selects base. For example:

-11> io:fwrite("~.16B~n", [31]).
+1> io:fwrite("~.16B~n", [31]).
 1F
 ok
-12> io:fwrite("~.2B~n", [-19]).
+2> io:fwrite("~.2B~n", [-19]).
 -10011
 ok
-13> io:fwrite("~.36B~n", [5*36+35]).
+3> io:fwrite("~.36B~n", [5*36+35]).
 5Z
 ok
@@ -590,10 +603,10 @@ ok

The prefix can be a possibly deep list of characters or an atom.

-14> io:fwrite("~X~n", [31,"10#"]).
+1> io:fwrite("~X~n", [31,"10#"]).
 10#31
 ok
-15> io:fwrite("~.16X~n", [-31,"0x"]).
+2> io:fwrite("~.16X~n", [-31,"0x"]).
 -0x1F
 ok
@@ -602,10 +615,10 @@ ok

Like B, but prints the number with an Erlang style #-separated base prefix.

-16> io:fwrite("~.10#~n", [31]).
+1> io:fwrite("~.10#~n", [31]).
 10#31
 ok
-17> io:fwrite("~.16#~n", [-31]).
+2> io:fwrite("~.16#~n", [-31]).
 -16#1F
 ok
@@ -639,10 +652,10 @@ ok

If an error occurs, there is no output. For example:

-18> io:fwrite("~s ~w ~i ~w ~c ~n",['abc def', 'abc def', {foo, 1},{foo, 1}, 65]).
+1> io:fwrite("~s ~w ~i ~w ~c ~n",['abc def', 'abc def', {foo, 1},{foo, 1}, 65]).
 abc def 'abc def'  {foo,1} A
 ok
-19> io:fwrite("~s", [65]).
+2> io:fwrite("~s", [65]).
 ** exception exit: {badarg,[{io,format,[<0.22.0>,"~s","A"]},
                             {erl_eval,do_apply,5},
                             {shell,exprs,6},
-- 
cgit v1.2.3