structured_io v0.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

The data matched in a scan

The data remaining after the match/0 in a scan

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 beginning with the specified after_data and ending with the specified before_data, exclusive

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

Link to this type match() View Source
match() :: binary()

The data matched in a scan.

Link to this type remainder() View Source
remainder() :: binary()

The data remaining after the match/0 in a scan.

Link to this section Functions

Link to this function scan_across(scan_data, from_data, through_data) View Source
scan_across(binary(), binary(), binary()) ::
  {match(), remainder()} |
  nil

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>>}
Link to this function scan_between(scan_data, after_data, before_data) View Source
scan_between(binary(), binary(), binary()) ::
  {match(), remainder()} |
  nil

Reads from the specified scan_data beginning with the specified after_data and ending with the specified before_data, exclusive.

If scan_data does not both begin with after_data and contain before_data, 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 <<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>>}
Link to this function scan_through(scan_data, through_data) View Source
scan_through(binary(), binary()) :: {match(), remainder()} | nil

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>>}
Link to this function scan_to(scan_data, to_data) View Source
scan_to(binary(), binary()) :: {match(), remainder()} | nil

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>>}