19962012 Ericsson AB. All Rights Reserved. The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. io_lib
io_lib IO 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. lists:flatten/1 can be used for flattening deep lists.

A continuation as returned by fread/3.

Write a newline

Returns a character list which represents a new line character.

Write a term

Returns a character list which represents Term. The Depth (-1) argument controls the depth of the structures written. When the specified depth is reached, everything below this level is replaced by "...". For 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],[...],...}"
Pretty print a term

Also returns a list of characters which represents Term, but breaks representations which are longer than one line into many lines and indents each line sensibly. It also tries to detect and output lists of printable characters as strings. Column is the starting column (1), LineLength the maximum line length (80), and Depth (-1) the maximum print depth.

Write formatted output

Returns a character list which represents Data formatted in accordance with Format. See io:fwrite/1,2,3 for a detailed description of the available formatting options. A fault is generated if there is an error in the format string or argument list.

If (and only if) the Unicode translation modifier is used in the format string (i.e. ~ts or ~tc), the resulting list may contain characters beyond the ISO-latin-1 character range (in other words, numbers larger than 255). If so, the result is not an ordinary Erlang string(), but can well be used in any context where Unicode data is allowed.

Read formatted input

Tries to read String in accordance with the control sequences in Format. See io:fread/3 for a detailed description of the available formatting options. It is assumed that String contains whole lines. It 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 in order to complete the original format string. RestFormat is the remaining format string, Nchars 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 the 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 []. Refer to Armstrong, Virding, Williams, 'Concurrent Programming in Erlang', Chapter 13 for a complete description of how the re-entrant input scheme works.

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 has been encountered. LeftOverChars are the input characters not used.

{error, What}

An error occurred and the 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.

Write an atom

Returns the list of characters needed to print the atom Atom.

Write a string

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

Write a character

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

Indentation after printing string

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

Test for a list of characters

Returns true if Term is a flat list of characters in the ISO-latin-1 range, otherwise it returns 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 it returns false.

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 it returns false.