19962018 Ericsson AB. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. io_lib
io_lib I/O library functions.

This module contains functions for converting to and from strings (lists of characters). They are used for implementing the functions in the io module. There is no guarantee that the character lists returned from some of the functions are flat, they can be deep lists. Function lists:flatten/1 can be used for flattening deep lists.

A continuation as returned by fread/3.

Where:

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 translation modifier t is present.

strings is set to false if modifier l is present.

Build the output text for a preparsed format list.

For details, see scan_format/2.

Test for a list of characters.

Returns true if Term is a flat list of characters in the Unicode range, otherwise false.

Test for a deep list of characters.

Returns true if Term is a, possibly deep, list of characters in the Unicode range, otherwise false.

Test for a deep list of characters.

Returns true if Term is a, possibly deep, list of characters in the ISO Latin-1 range, otherwise false.

Write formatted output.

Returns a character list that represents Data formatted in accordance with Format. For a detailed description of the available formatting options, see io:fwrite/1,2,3. If the format string or argument list contains an error, a fault is generated.

If and only if the Unicode translation modifier is used in the format string (that is, ~ts or ~tc), the resulting list can contain characters beyond the ISO Latin-1 character range (that is, numbers > 255). If so, the result is still an ordinary Erlang string(), and can well be used in any context where Unicode data is allowed.

Write formatted output.

Returns a character list that represents Data formatted in accordance with Format in the same way as fwrite/2 and format/2, but takes an extra argument, a list of options.

Available options:

CharsLimit

A soft limit on the number of characters returned.

Read formatted input.

Tries to read String in accordance with the control sequences in Format. For a detailed description of the available formatting options, see io:fread/3. It is assumed that String contains whole lines.

The function returns:

{ok, InputList, LeftOverChars}

The string was read. InputList is the list of successfully matched and read items, and LeftOverChars are the input characters not used.

{more, RestFormat, Nchars, InputStack}

The string was read, but more input is needed to complete the original format string. RestFormat is the remaining format string, Nchars is the number of characters scanned, and InputStack is the reversed list of inputs matched up to that point.

{error, What}

The read operation failed and parameter What gives a hint about the error.

Example:

3> io_lib:fread("~f~f~f", "15.6 17.3e-6 24.5").
{ok,[15.6,1.73e-5,24.5],[]}
Re-entrant formatted reader

This is the re-entrant formatted reader. The continuation of the first call to the functions must be []. For a complete description of how the re-entrant input scheme works, see Armstrong, Virding, Williams: 'Concurrent Programming in Erlang', Chapter 13.

The function returns:

{done, Result, LeftOverChars}

The input is complete. The result is one of the following:

{ok, InputList}

The string was read. InputList is the list of successfully matched and read items, and LeftOverChars are the remaining characters.

eof

End of file was encountered. LeftOverChars are the input characters not used.

{error, What}

An error occurred and parameter What gives a hint about the error.

{more, Continuation}

More data is required to build a term. Continuation must be passed to fread/3 when more data becomes available.

Indentation after printing string.

Returns the indentation if String has been printed, starting at StartIndent.

Test for a list of ISO Latin-1 characters.

Returns true if Term is a flat list of characters in the ISO Latin-1 range, otherwise false.

Write a newline.

Returns a character list that represents a new line character.

Pretty print a term.

Returns a list of characters that represents Term, but breaks representations longer than one line into many lines and indents each line sensibly. Also tries to detect and output lists of printable characters as strings.

Column is the starting column; defaults to 1. LineLength is the maximum line length; defaults to 80. Depth is the maximum print depth; defaults to -1, which means no limitation.
Test for a list of printable ISO Latin-1 characters.

Returns true if Term is a flat list of printable ISO Latin-1 characters, otherwise false.

Test for a list of printable characters.

Returns true if Term is a flat list of printable characters, otherwise false.

What is a printable character in this case is determined by startup flag +pc to the Erlang VM; see io:printable_range/0 and erl(1).

Test for a list of printable Unicode characters.

Returns true if Term is a flat list of printable Unicode characters, otherwise false.

Parse all control sequences in the format string.

Returns a list corresponding to the specified format string, where control sequences have been replaced with corresponding tuples. This list can be passed to:

build_text/1 to have the same effect as format(Format, Args)

unscan_format/1 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 in, for example, a logger.

Revert a preparsed format list to a plain character list and a list of arguments.

For details, see scan_format/2.

Write a term.

Returns a character list that represents Term. Option Depth controls the depth of the structures written. When the specified depth is reached, everything below this level is replaced by "...". Depth defaults to -1, which means no limitation. Option CharsLimit puts a soft limit on the number of characters returned. When the number of characters is reached, remaining structures are replaced by "...". CharsLimit defaults to -1, which means no limit on the number of characters returned.

Example:

1> lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9})).
"{1,[2],[3],[4,5],6,7,8,9}"
2> lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9}, 5)).
"{1,[2],[3],[...],...}"
3> lists:flatten(io_lib:write({[1,2,3],[4,5],6,7,8,9}, [{chars_limit,20}])).
"{[1,2|...],[4|...],...}"
Write an atom.

Returns the list of characters needed to print atom Atom.

Write an atom.

Returns the list of characters needed to print atom Atom. Non-Latin-1 characters are escaped.

Write a character.

Returns the list of characters needed to print a character constant in the Unicode character set.

Write a character.

Returns the list of characters needed to print a character constant in the Unicode character set. Non-Latin-1 characters are escaped.

Write an ISO Latin-1 character.

Returns the list of characters needed to print a character constant in the ISO Latin-1 character set.

Write an ISO Latin-1 string.

Returns the list of characters needed to print Latin1String as a string.

Write a string.

Returns the list of characters needed to print String as a string.

Write a string.

Returns the list of characters needed to print String as a string. Non-Latin-1 characters are escaped.