structured_io v0.7.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
, 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 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.
Link to this section Functions
Reads from the specified data
, beginning with the specified left
and
ending with the occurrence of the specified right
that corresponds to it,
inclusive.
When the region — bounded by the first occurrence of left
and the occurrence
right
that corresponds to it — overlaps other such regions, the result is
the union of the regions. 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>>}