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

t()

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

comparison()
comparison() :: :eq | :gt | :lt

The result of comparing two components

delete()
delete() :: %{d: OT.Text.datum}

A delete component, in which a string of zero or more characters are deleted from the text

insert()
insert() :: %{i: OT.Text.datum}

An insert component, in which a string of zero or more characters are inserted into the text

retain()
retain() :: non_neg_integer

A retain component, in which a number of characters in the text are skipped over

t()
t() :: delete | insert | retain

A single unit of “work” performed on a piece of text

type()
type() :: :delete | :insert | :retain

An atom declaring the type of a component

Functions

compare(comp_a, comp_b)
compare(t, t) :: comparison

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(comp)
invert(t) :: t

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(retain_a, retain_b)
join(t, t) :: OT.Text.Operation.t

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"}]
length(comp)
length(t) :: non_neg_integer

Determine the length of a component.

Examples

iex> OT.Text.Component.length(4)
4

iex> OT.Text.Component.length(%{i: "Foo"})
3
no_op?(arg1)
no_op?(t) :: boolean

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
split(comp, index)
split(t, non_neg_integer) :: {t, t}

Split a component at a given index.

Returns a tuple containing a new component before the index, and a new component after the index.

Examples

iex> OT.Text.Component.split(4, 3)
{3, 1}

iex> OT.Text.Component.split(%{i: "Foo"}, 2)
{%{i: "Fo"}, %{i: "o"}}
type(comp)
type(t) :: type

Determine the type of a component.

Examples

iex> OT.Text.Component.type(4)
:retain

iex> OT.Text.Component.type(%{i: "Foo"})
:insert

iex> OT.Text.Component.type(%{d: "Foo"})
:delete