structured_io v0.3.0 StructuredIO.Scanner View Source
Provides functions for decomposing structured data, such as markup or binary-encoded data.
Link to this section Summary
Functions
Reads from the specified scan_data
beginning with the specified from_data
and ending with the specified through_data
, inclusive
Reads from the specified scan_data
if and until the specified through_data
is encountered, including through_data
Reads from the specified scan_data
if and until the specified to_data
is
encountered, excluding to_data
Link to this section Types
The data matched in a scan.
The data remaining after the match/0
in a scan.
Link to this section Functions
Reads from the specified scan_data
beginning with the specified from_data
and ending with the specified through_data
, inclusive.
If scan_data
does not both begin with from_data
and contain
through_data
, the result is nil
.
Examples
iex> StructuredIO.Scanner.scan_across "<elem>foo</elem",
...> "<elem>",
...> "</elem>"
nil
iex> StructuredIO.Scanner.scan_across "<elem>foo</elem><elem>bar</elem>",
...> "<elem>",
...> "</elem>"
{"<elem>foo</elem>",
"<elem>bar</elem>"}
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, 255, 255, 255, 0, 0, 0, 4, 5, 6, 255, 255, 255>>,
...> <<0, 0, 0>>,
...> <<255, 255, 255>>
{<<0, 0, 0, 1, 2, 3, 255, 255, 255>>,
<<0, 0, 0, 4, 5, 6, 255, 255, 255>>}
Reads from the specified scan_data
if and until the specified through_data
is encountered, including through_data
.
If scan_data
does not contain through_data
, 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 scan_data
if and until the specified to_data
is
encountered, excluding to_data
.
If scan_data
does not contain to_data
, 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>>}