OT v0.1.0 OT.Text.Component
An individual unit of work to be performed on a piece of text.
A component represents a retain or modification of the text:
5
: Retain 5 characters of the text%{i:"Hello"}
: Insert the string “Hello”%{d:"World"}
: Delete the string “World”
Summary
Types
The result of comparing two components
A delete component, in which a string of zero or more characters are deleted from the text
An insert component, in which a string of zero or more characters are inserted into the text
A retain component, in which a number of characters in the text are skipped over
A single unit of “work” performed on a piece of text
An atom declaring the type of a component
Functions
Compare the length of two components
Invert a component
Join two components into an operation, combining them into a single component if they are of the same type
Determine the length of a component
Determine whether a comopnent is a no-op
Split a component at a given index
Determine the type of a component
Types
A delete component, in which a string of zero or more characters are deleted from the text
An insert component, in which a string of zero or more characters are inserted into the text
A retain component, in which a number of characters in the text are skipped over
Functions
Compare the length of two components.
Will return :gt
if first is greater than second, :lt
if first is less
than second, or :eq
if they span equal lengths.
Example
iex> OT.Text.Component.compare(%{i: "Foo"}, 1)
:gt
Invert a component.
Examples
iex> OT.Text.Component.invert(%{i: "Foo"})
%{d: "Foo"}
iex> OT.Text.Component.invert(%{d: "Foo"})
%{i: "Foo"}
iex> OT.Text.Component.invert(4)
4
Join two components into an operation, combining them into a single component if they are of the same type.
Example
iex> OT.Text.Component.join(%{i: "Foo"}, %{i: "Bar"})
[%{i: "FooBar"}]
Determine the length of a component.
Examples
iex> OT.Text.Component.length(4)
4
iex> OT.Text.Component.length(%{i: "Foo"})
3
Determine whether a comopnent is a no-op.
Examples
iex> OT.Text.Component.no_op?(0)
true
iex> OT.Text.Component.no_op?(%{i: ""})
true