1io_lib(3)                  Erlang Module Definition                  io_lib(3)
2
3
4

NAME

6       io_lib - I/O library functions.
7

DESCRIPTION

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

DATA TYPES

16       chars() = [char() | chars()]
17
18       continuation()
19
20              A continuation as returned by fread/3.
21
22       depth() = -1 | integer() >= 0
23
24       fread_error() =
25           atom |
26           based |
27           character |
28           float |
29           format |
30           input |
31           integer |
32           string |
33           unsigned
34
35       fread_item() = string() | atom() | integer() | float()
36
37       latin1_string() = [unicode:latin1_char()]
38
39       format_spec() =
40           #{control_char := char(),
41             args := [any()],
42             width := none | integer(),
43             adjust := left | right,
44             precision := none | integer(),
45             pad_char := char(),
46             encoding := unicode | latin1,
47             strings := boolean()}
48
49              Where:
50
51                * control_char is the type of control sequence: $P, $w, and so
52                  on.
53
54                * args is  a  list  of  the  arguments  used  by  the  control
55                  sequence,  or an empty list if the control sequence does not
56                  take any arguments.
57
58                * width is the field width.
59
60                * adjust is the adjustment.
61
62                * precision is the precision of the printed argument.
63
64                * pad_char is the padding character.
65
66                * encoding is  set  to  true  if  translation  modifier  t  is
67                  present.
68
69                * strings is set to false if modifier l is present.
70

EXPORTS

72       build_text(FormatList) -> chars()
73
74              Types:
75
76                 FormatList = [char() | format_spec()]
77
78              For details, see scan_format/2.
79
80       char_list(Term) -> boolean()
81
82              Types:
83
84                 Term = term()
85
86              Returns true if Term is a flat list of characters in the Unicode
87              range, otherwise false.
88
89       deep_char_list(Term) -> boolean()
90
91              Types:
92
93                 Term = term()
94
95              Returns true if Term is a, possibly deep, list of characters  in
96              the Unicode range, otherwise false.
97
98       deep_latin1_char_list(Term) -> boolean()
99
100              Types:
101
102                 Term = term()
103
104              Returns  true if Term is a, possibly deep, list of characters in
105              the ISO Latin-1 range, otherwise false.
106
107       format(Format, Data) -> chars()
108
109       fwrite(Format, Data) -> chars()
110
111              Types:
112
113                 Format = io:format()
114                 Data = [term()]
115
116              Returns a character  list  that  represents  Data  formatted  in
117              accordance with Format. For a detailed description of the avail‐
118              able formatting options,  see  io:fwrite/1,2,3.  If  the  format
119              string or argument list contains an error, a fault is generated.
120
121              If  and  only if the Unicode translation modifier is used in the
122              format string (that is, ~ts or ~tc), the resulting list can con‐
123              tain characters beyond the ISO Latin-1 character range (that is,
124              numbers > 255). If so, the result is still  an  ordinary  Erlang
125              string(), and can well be used in any context where Unicode data
126              is allowed.
127
128       fread(Format, String) -> Result
129
130              Types:
131
132                 Format = String = string()
133                 Result =
134                     {ok,  InputList  ::  [fread_item()],   LeftOverChars   ::
135                 string()} |
136                     {more,
137                      RestFormat :: string(),
138                      Nchars :: integer() >= 0,
139                      InputStack :: chars()} |
140                     {error, {fread, What :: fread_error()}}
141
142              Tries to read String in accordance with the control sequences in
143              Format. For a detailed description of the  available  formatting
144              options,  see  io:fread/3.  It  is  assumed that String contains
145              whole lines.
146
147              The function returns:
148
149                {ok, InputList, LeftOverChars}:
150                  The string was read. InputList is the list  of  successfully
151                  matched  and  read  items,  and  LeftOverChars are the input
152                  characters not used.
153
154                {more, RestFormat, Nchars, InputStack}:
155                  The string was read, but more input is  needed  to  complete
156                  the original format string. RestFormat is the remaining for‐
157                  mat string, Nchars is the number of characters scanned,  and
158                  InputStack is the reversed list of inputs matched up to that
159                  point.
160
161                {error, What}:
162                  The read operation failed and parameter What  gives  a  hint
163                  about the error.
164
165              Example:
166
167              3> io_lib:fread("~f~f~f", "15.6 17.3e-6 24.5").
168              {ok,[15.6,1.73e-5,24.5],[]}
169
170       fread(Continuation, CharSpec, Format) -> Return
171
172              Types:
173
174                 Continuation = continuation() | []
175                 CharSpec = string() | eof
176                 Format = string()
177                 Return =
178                     {more, Continuation1 :: continuation()} |
179                     {done, Result, LeftOverChars :: string()}
180                 Result =
181                     {ok, InputList :: [fread_item()]} |
182                     eof |
183                     {error, {fread, What :: fread_error()}}
184
185              This is the re-entrant formatted reader. The continuation of the
186              first call to the functions must be []. For a complete  descrip‐
187              tion  of  how  the re-entrant input scheme works, see Armstrong,
188              Virding, Williams: 'Concurrent Programming in  Erlang',  Chapter
189              13.
190
191              The function returns:
192
193                {done, Result, LeftOverChars}:
194                  The input is complete. The result is one of the following:
195
196                  {ok, InputList}:
197                    The string was read. InputList is the list of successfully
198                    matched and read items, and LeftOverChars are the  remain‐
199                    ing characters.
200
201                  eof:
202                    End  of  file was encountered. LeftOverChars are the input
203                    characters not used.
204
205                  {error, What}:
206                    An error occurred and parameter What gives  a  hint  about
207                    the error.
208
209                {more, Continuation}:
210                  More  data is required to build a term. Continuation must be
211                  passed to fread/3 when more data becomes available.
212
213       indentation(String, StartIndent) -> integer()
214
215              Types:
216
217                 String = string()
218                 StartIndent = integer()
219
220              Returns the indentation if String has been printed, starting  at
221              StartIndent.
222
223       latin1_char_list(Term) -> boolean()
224
225              Types:
226
227                 Term = term()
228
229              Returns  true  if  Term  is a flat list of characters in the ISO
230              Latin-1 range, otherwise false.
231
232       nl() -> string()
233
234              Returns a character list that represents a new line character.
235
236       print(Term) -> chars()
237
238       print(Term, Column, LineLength, Depth) -> chars()
239
240              Types:
241
242                 Term = term()
243                 Column = LineLength = integer() >= 0
244                 Depth = depth()
245
246              Returns a list of characters that represents  Term,  but  breaks
247              representations longer than one line into many lines and indents
248              each line sensibly. Also tries to detect  and  output  lists  of
249              printable characters as strings.
250
251                * Column is the starting column; defaults to 1.
252
253                * LineLength is the maximum line length; defaults to 80.
254
255                * Depth  is  the  maximum  print  depth; defaults to -1, which
256                  means no limitation.
257
258       printable_latin1_list(Term) -> boolean()
259
260              Types:
261
262                 Term = term()
263
264              Returns true if Term is a flat list  of  printable  ISO  Latin-1
265              characters, otherwise false.
266
267       printable_list(Term) -> boolean()
268
269              Types:
270
271                 Term = term()
272
273              Returns  true  if  Term  is a flat list of printable characters,
274              otherwise false.
275
276              What is a printable character in  this  case  is  determined  by
277              startup  flag +pc to the Erlang VM; see io:printable_range/0 and
278              erl(1).
279
280       printable_unicode_list(Term) -> boolean()
281
282              Types:
283
284                 Term = term()
285
286              Returns true if Term is a flat list of printable Unicode charac‐
287              ters, otherwise false.
288
289       scan_format(Format, Data) -> FormatList
290
291              Types:
292
293                 Format = io:format()
294                 Data = [term()]
295                 FormatList = [char() | format_spec()]
296
297              Returns  a  list  corresponding  to the specified format string,
298              where control sequences have been  replaced  with  corresponding
299              tuples. This list can be passed to:
300
301                * build_text/1 to have the same effect as format(Format, Args)
302
303                * unscan_format/1  to get the corresponding pair of Format and
304                  Args (with every * and corresponding  argument  expanded  to
305                  numeric values)
306
307              A typical use of this function is to replace unbounded-size con‐
308              trol sequences like ~w and ~p with the depth-limited variants ~W
309              and ~P before formatting to text in, for example, a logger.
310
311       unscan_format(FormatList) -> {Format, Data}
312
313              Types:
314
315                 FormatList = [char() | format_spec()]
316                 Format = io:format()
317                 Data = [term()]
318
319              For details, see scan_format/2.
320
321       write(Term) -> chars()
322
323       write(Term, Depth) -> chars()
324
325       write(Term, Options) -> chars()
326
327              Types:
328
329                 Term = term()
330                 Options = [Option]
331                 Option = {depth, Depth} | {encoding, latin1 | utf8 | unicode}
332                 Depth = depth()
333
334              Returns  a  character  list that represents Term. Argument Depth
335              controls the depth of the structures written. When the specified
336              depth  is  reached,  everything  below this level is replaced by
337              "...". Depth defaults to -1, which means no limitation.
338
339              Example:
340
341              1> lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9})).
342              "{1,[2],[3],[4,5],6,7,8,9}"
343              2> lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9}, 5)).
344              "{1,[2],[3],[...],...}"
345
346       write_atom(Atom) -> chars()
347
348              Types:
349
350                 Atom = atom()
351
352              Returns the list of characters needed to print atom Atom.
353
354       write_atom_as_latin1(Atom) -> latin1_string()
355
356              Types:
357
358                 Atom = atom()
359
360              Returns the list of characters needed to print atom  Atom.  Non-
361              Latin-1 characters are escaped.
362
363       write_char(Char) -> chars()
364
365              Types:
366
367                 Char = char()
368
369              Returns  the list of characters needed to print a character con‐
370              stant in the Unicode character set.
371
372       write_char_as_latin1(Char) -> latin1_string()
373
374              Types:
375
376                 Char = char()
377
378              Returns the list of characters needed to print a character  con‐
379              stant  in  the Unicode character set. Non-Latin-1 characters are
380              escaped.
381
382       write_latin1_char(Latin1Char) -> latin1_string()
383
384              Types:
385
386                 Latin1Char = unicode:latin1_char()
387
388              Returns the list of characters needed to print a character  con‐
389              stant in the ISO Latin-1 character set.
390
391       write_latin1_string(Latin1String) -> latin1_string()
392
393              Types:
394
395                 Latin1String = latin1_string()
396
397              Returns the list of characters needed to print Latin1String as a
398              string.
399
400       write_string(String) -> chars()
401
402              Types:
403
404                 String = string()
405
406              Returns the list of characters  needed  to  print  String  as  a
407              string.
408
409       write_string_as_latin1(String) -> latin1_string()
410
411              Types:
412
413                 String = string()
414
415              Returns  the  list  of  characters  needed  to print String as a
416              string. Non-Latin-1 characters are escaped.
417
418
419
420Ericsson AB                     stdlib 3.4.5.1                       io_lib(3)
Impressum