structured_io v1.5.0 StructuredIO.Scanner View Source
Provides functions for decomposing structured data, such as markup or binary-encoded data.
Link to this section Summary
Types
A binary value which marks the beginning of an enclosed data element
The portion of a binary value matched in a scan
The portion of a binary value remaining after the match/0
in a scan
A binary value which marks the end of an enclosed or terminated data element
Functions
Reads from the specified data
in the specified quantity. The quantity is
measured as a count
of a particular unit
Reads from the specified data
, beginning with the specified left
and
ending with the occurrence of the specified right
that corresponds to it,
inclusive
Reads from the specified data
, beginning with the specified left
and
ending with the first occurrence of the specified right
, inclusive
Reads from the specified data
, beginning with the specified left
and
ending with the occurrence of the specified right
that corresponds to it,
exclusive
Reads from the specified data
, beginning with the specified left
and
ending with the first occurrence of the specified right
, exclusive
Reads from the specified data
if and until the specified right
is
encountered, including right
Reads from the specified data
if and until the specified right
is
encountered, excluding right
Link to this section Types
A measure of size for a measured data element. See unit/0
.
A binary value which marks the beginning of an enclosed data element.
The portion of a binary value matched in a scan.
The portion of a binary value remaining after the match/0
in a scan.
A binary value which marks the end of an enclosed or terminated data element.
The unit of size for a measured data element: either bytes or graphemes. See
count/0
.
Link to this section Functions
Reads from the specified data
in the specified quantity. The quantity is
measured as a count
of a particular unit
.
If the process does not contain at least the expected quantity of data, the
result is nil
.
Examples
iex> StructuredIO.Scanner.scan "\r\nfoo",
...> :graphemes,
...> 5
nil
iex> StructuredIO.Scanner.scan "\r\nfoo\tbar",
...> :graphemes,
...> 5
{"\r\nfoo\t",
"bar"}
iex> StructuredIO.Scanner.scan <<23, 45>>,
...> :bytes,
...> 3
nil
iex> StructuredIO.Scanner.scan <<23, 45, 67, 89>>,
...> :bytes,
...> 3
{<<23, 45, 67>>,
<<89>>}
Reads from the specified data
, beginning with the specified left
and
ending with the occurrence of the specified right
that corresponds to it,
inclusive.
If data
does not both begin with left
and contain a corresponding right
,
the result is nil
.
Examples
iex> StructuredIO.Scanner.scan_across "<elem>foo</elem",
...> "<elem>",
...> "</elem>"
nil
iex> StructuredIO.Scanner.scan_across "<elem>foo<elem>bar</elem></elem>baz",
...> "<elem>",
...> "</elem>"
{"<elem>foo<elem>bar</elem></elem>",
"baz"}
iex> StructuredIO.Scanner.scan_across <<0, 0, 0, 1, 2, 3, 255, 255>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
nil
iex> StructuredIO.Scanner.scan_across <<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255, 255, 255, 255, 255, 7, 8, 9>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
{<<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255, 255, 255, 255, 255>>,
<<7, 8, 9>>}
Reads from the specified data
, beginning with the specified left
and
ending with the first occurrence of the specified right
, inclusive.
If data
does not both begin with left
and contain right
, the result is
nil
.
Examples
iex> StructuredIO.Scanner.scan_across_ignoring_overlap "<elem>foo<elem>bar</elem",
...> "<elem>",
...> "</elem>"
nil
iex> StructuredIO.Scanner.scan_across_ignoring_overlap "<elem>foo<elem>bar</elem></elem>baz",
...> "<elem>",
...> "</elem>"
{"<elem>foo<elem>bar</elem>",
"</elem>baz"}
iex> StructuredIO.Scanner.scan_across_ignoring_overlap <<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
nil
iex> StructuredIO.Scanner.scan_across_ignoring_overlap <<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255, 255, 255, 255, 255, 7, 8, 9>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
{<<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255, 255>>,
<<255, 255, 255, 7, 8, 9>>}
Reads from the specified data
, beginning with the specified left
and
ending with the occurrence of the specified right
that corresponds to it,
exclusive.
If data
does not both begin with left
and contain a corresponding right
,
the result is nil
.
Examples
iex> StructuredIO.Scanner.scan_between "<elem>foo</elem",
...> "<elem>",
...> "</elem>"
nil
iex> StructuredIO.Scanner.scan_between "<elem>foo</elem><elem>bar</elem>",
...> "<elem>",
...> "</elem>"
{"foo",
"<elem>bar</elem>"}
iex> StructuredIO.Scanner.scan_between "<elem>foo<elem>bar</elem></elem>baz",
...> "<elem>",
...> "</elem>"
{"foo<elem>bar</elem>",
"baz"}
iex> StructuredIO.Scanner.scan_between <<0, 0, 0, 1, 2, 3, 255, 255>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
nil
iex> StructuredIO.Scanner.scan_between <<0, 0, 0, 1, 2, 3, 255, 255, 255, 0, 0, 0, 4, 5, 6, 255, 255, 255>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
{<<1, 2, 3>>,
<<0, 0, 0, 4, 5, 6, 255, 255, 255>>}
iex> StructuredIO.Scanner.scan_between <<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255, 255, 255, 255, 255, 7, 8, 9>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
{<<1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255, 255>>,
<<7, 8, 9>>}
Reads from the specified data
, beginning with the specified left
and
ending with the first occurrence of the specified right
, exclusive.
If data
does not both begin with left
and contain right
, the result is
nil
.
Examples
iex> StructuredIO.Scanner.scan_between_ignoring_overlap "<elem>foo<elem>bar</elem",
...> "<elem>",
...> "</elem>"
nil
iex> StructuredIO.Scanner.scan_between_ignoring_overlap "<elem>foo<elem>bar</elem></elem>baz",
...> "<elem>",
...> "</elem>"
{"foo<elem>bar",
"</elem>baz"}
iex> StructuredIO.Scanner.scan_between_ignoring_overlap <<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
nil
iex> StructuredIO.Scanner.scan_between_ignoring_overlap <<0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 5, 6, 255, 255, 255, 255, 255, 255, 7, 8, 9>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
{<<1, 2, 3, 0, 0, 0, 4, 5, 6>>,
<<255, 255, 255, 7, 8, 9>>}
Reads from the specified data
if and until the specified right
is
encountered, including right
.
If data
does not contain right
, the result is nil
.
Examples
iex> StructuredIO.Scanner.scan_through "foo<br /",
...> "<br/>"
nil
iex> StructuredIO.Scanner.scan_through "foo<br/>bar<br/>",
...> "<br/>"
{"foo<br/>",
"bar<br/>"}
iex> StructuredIO.Scanner.scan_through <<1, 2, 3, 255, 255>>,
...> <<255, 255, 255>>
nil
iex> StructuredIO.Scanner.scan_through <<1, 2, 3, 255, 255, 255, 4, 5, 6, 255, 255, 255>>,
...> <<255, 255, 255>>
{<<1, 2, 3, 255, 255, 255>>,
<<4, 5, 6, 255, 255, 255>>}
Reads from the specified data
if and until the specified right
is
encountered, excluding right
.
If data
does not contain right
, the result is nil
.
Examples
iex> StructuredIO.Scanner.scan_to "foo<br /",
...> "<br/>"
nil
iex> StructuredIO.Scanner.scan_to "foo<br/>bar<br/>",
...> "<br/>"
{"foo",
"<br/>bar<br/>"}
iex> StructuredIO.Scanner.scan_to <<1, 2, 3, 255, 255>>,
...> <<255, 255, 255>>
nil
iex> StructuredIO.Scanner.scan_to <<1, 2, 3, 255, 255, 255, 4, 5, 6, 255, 255, 255>>,
...> <<255, 255, 255>>
{<<1, 2, 3>>,
<<255, 255, 255, 4, 5, 6, 255, 255, 255>>}