1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
32
<module>io_lib</module>
33
<modulesummary>IO Library Functions</modulesummary>
35
<p>This module contains functions for converting to and from
36
strings (lists of characters). They are used for implementing the
37
functions in the <c>io</c> module. There is no guarantee that the
38
character lists returned from some of the functions are flat,
39
they can be deep lists. <c>lists:flatten/1</c> can be used for
40
flattening deep lists.</p>
44
<title>DATA TYPES</title>
46
chars() = [char() | chars()]</code>
50
<name>nl() -> chars()</name>
51
<fsummary>Write a newline</fsummary>
53
<p>Returns a character list which represents a new line
58
<name>write(Term) -></name>
59
<name>write(Term, Depth) -> chars()</name>
60
<fsummary>Write a term</fsummary>
66
<p>Returns a character list which represents <c>Term</c>. The
67
<c>Depth</c> (-1) argument controls the depth of the
68
structures written. When the specified depth is reached,
69
everything below this level is replaced by "...". For
72
1> <input>lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9})).</input>
73
"{1,[2],[3],[4,5],6,7,8,9}"
74
2> <input>lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9}, 5)).</input>
75
"{1,[2],[3],[...],...}"</pre>
79
<name>print(Term) -></name>
80
<name>print(Term, Column, LineLength, Depth) -> chars()</name>
81
<fsummary>Pretty print a term</fsummary>
84
<v>Column = LineLenght = Depth = int()</v>
87
<p>Also returns a list of characters which represents
88
<c>Term</c>, but breaks representations which are longer than
89
one line into many lines and indents each line sensibly. It
90
also tries to detect and output lists of printable characters
91
as strings. <c>Column</c> is the starting column (1),
92
<c>LineLength</c> the maximum line length (80), and
93
<c>Depth</c> (-1) the maximum print depth.</p>
97
<name>fwrite(Format, Data) -></name>
98
<name>format(Format, Data) -> chars()</name>
99
<fsummary>Write formatted output</fsummary>
101
<v>Format = atom() | string() | binary()</v>
102
<v>Data = [term()]</v>
105
<p>Returns a character list which represents <c>Data</c>
106
formatted in accordance with <c>Format</c>. See
107
<seealso marker="io#fwrite/1">io:fwrite/1,2,3</seealso> for a detailed
108
description of the available formatting options. A fault is
109
generated if there is an error in the format string or
114
<name>fread(Format, String) -> Result</name>
115
<fsummary>Read formatted input</fsummary>
117
<v>Format = String = string()</v>
118
<v>Result = {ok, InputList, LeftOverChars} | {more, RestFormat, Nchars, InputStack} | {error, What}</v>
119
<v> InputList = chars()</v>
120
<v> LeftOverChars = string()</v>
121
<v> RestFormat = string()</v>
122
<v> Nchars = int()</v>
123
<v> InputStack = chars()</v>
124
<v> What = term()</v>
127
<p>Tries to read <c>String</c> in accordance with the control
128
sequences in <c>Format</c>. See
129
<seealso marker="io#fread/3">io:fread/3</seealso> for a detailed
130
description of the available formatting options. It is
131
assumed that <c>String</c> contains whole lines. It returns:</p>
133
<tag><c>{ok, InputList, LeftOverChars}</c></tag>
135
<p>The string was read. <c>InputList</c> is the list of
136
successfully matched and read items, and
137
<c>LeftOverChars</c> are the input characters not used.</p>
139
<tag><c>{more, RestFormat, Nchars, InputStack}</c></tag>
141
<p>The string was read, but more input is needed in order
142
to complete the original format string. <c>RestFormat</c>
143
is the remaining format string, <c>NChars</c> the number
144
of characters scanned, and <c>InputStack</c> is the
145
reversed list of inputs matched up to that point.</p>
147
<tag><c>{error, What}</c></tag>
149
<p>The read operation failed and the parameter <c>What</c>
150
gives a hint about the error.</p>
155
3> <input>io_lib:fread("~f~f~f", "15.6 17.3e-6 24.5").</input>
156
{ok,[15.6,1.73e-5,24.5],[]}</pre>
160
<name>fread(Continuation, String, Format) -> Return</name>
161
<fsummary>Re-entrant formatted reader</fsummary>
163
<v>Continuation = see below</v>
164
<v>String = Format = string()</v>
165
<v>Return = {done, Result, LeftOverChars} | {more, Continuation}</v>
166
<v> Result = {ok, InputList} | eof | {error, What}</v>
167
<v> InputList = chars()</v>
168
<v> What = term()()</v>
169
<v> LeftOverChars = string()</v>
172
<p>This is the re-entrant formatted reader. The continuation of
173
the first call to the functions must be <c>[]</c>. Refer to
174
Armstrong, Virding, Williams, 'Concurrent Programming in
175
Erlang', Chapter 13 for a complete description of how the
176
re-entrant input scheme works.</p>
177
<p>The function returns:</p>
179
<tag><c>{done, Result, LeftOverChars}</c></tag>
181
<p>The input is complete. The result is one of the
184
<tag><c>{ok, InputList}</c></tag>
186
<p>The string was read. <c>InputList</c> is the list of
187
successfully matched and read items, and
188
<c>LeftOverChars</c> are the remaining characters.</p>
190
<tag><c>eof</c></tag>
192
<p>End of file has been encountered.
193
<c>LeftOverChars</c> are the input characters not
196
<tag><c>{error, What}</c></tag>
198
<p>An error occurred and the parameter <c>What</c> gives
199
a hint about the error.</p>
203
<tag><c>{more, Continuation}</c></tag>
205
<p>More data is required to build a term.
206
<c>Continuation</c> must be passed to <c>fread/3</c>,
207
when more data becomes available.</p>
213
<name>write_atom(Atom) -> chars()</name>
214
<fsummary>Write an atom</fsummary>
219
<p>Returns the list of characters needed to print the atom
224
<name>write_string(String) -> chars()</name>
225
<fsummary>Write a string</fsummary>
227
<v>String = string()</v>
230
<p>Returns the list of characters needed to print <c>String</c>
235
<name>write_char(Integer) -> chars()</name>
236
<fsummary>Write a character</fsummary>
238
<v>Integer = int()</v>
241
<p>Returns the list of characters needed to print a character
246
<name>indentation(String, StartIndent) -> int()</name>
247
<fsummary>Indentation after printing string</fsummary>
249
<v>String = string()</v>
250
<v>StartIndent = int()</v>
253
<p>Returns the indentation if <c>String</c> has been printed,
254
starting at <c>StartIndent</c>.</p>
258
<name>char_list(Term) -> bool()</name>
259
<fsummary>Test for a list of characters</fsummary>
264
<p>Returns <c>true</c> if <c>Term</c> is a flat list of
265
characters, otherwise it returns <c>false</c>.</p>
269
<name>deep_char_list(Term) -> bool()</name>
270
<fsummary>Test for a deep list of characters</fsummary>
275
<p>Returns <c>true</c> if <c>Term</c> is a, possibly deep, list
276
of characters, otherwise it returns <c>false</c>.</p>
280
<name>printable_list(Term) -> bool()</name>
281
<fsummary>Test for a list of printable characters</fsummary>
286
<p>Returns <c>true</c> if <c>Term</c> is a flat list of
287
printable characters, otherwise it returns <c>false</c>.</p>