LeXtract.CharInterval (lextract v0.1.2)
View SourceRepresents a character position interval in text.
Fields
:start_pos- Starting character position (0-based, inclusive):end_pos- Ending character position (0-based, exclusive)
Examples
iex> interval = %LeXtract.CharInterval{start_pos: 0, end_pos: 5}
iex> LeXtract.CharInterval.length(interval)
5
Summary
Functions
Extracts text from a string using this interval.
Returns the length of the interval.
Creates a new character interval.
Checks if two intervals overlap.
Types
@type t() :: %LeXtract.CharInterval{ end_pos: non_neg_integer(), start_pos: non_neg_integer() }
Functions
Extracts text from a string using this interval.
Examples
iex> interval = LeXtract.CharInterval.new(0, 5)
iex> LeXtract.CharInterval.extract("Hello, world!", interval)
"Hello"
@spec length(t()) :: non_neg_integer()
Returns the length of the interval.
Examples
iex> interval = LeXtract.CharInterval.new(10, 20)
iex> LeXtract.CharInterval.length(interval)
10
@spec new(non_neg_integer(), non_neg_integer()) :: t()
Creates a new character interval.
Examples
iex> LeXtract.CharInterval.new(0, 10)
%LeXtract.CharInterval{start_pos: 0, end_pos: 10}
Checks if two intervals overlap.
Examples
iex> i1 = LeXtract.CharInterval.new(0, 5)
iex> i2 = LeXtract.CharInterval.new(3, 8)
iex> LeXtract.CharInterval.overlaps?(i1, i2)
true
iex> i1 = LeXtract.CharInterval.new(0, 5)
iex> i2 = LeXtract.CharInterval.new(5, 10)
iex> LeXtract.CharInterval.overlaps?(i1, i2)
false