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

Link to this section Types

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

The data matched in a scan.

Link to this type remaining() View Source
remaining() :: 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(), remaining()} |
  nil

Reads from the specified scan_data beginning with the specified from_data and ending with the specified through_data.

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