View Source PieceTable.Differ (piece_table v0.1.4)
A module to calculate the difference between a text and another text or a piece table.
usage
Usage
iex> PieceTable.Differ.diff("test", "text")
{:ok,
%PieceTable{
original: "test",
result: "text",
applied: [
%PieceTable.Change{change: :ins, text: "x", position: 2},
%PieceTable.Change{change: :del, text: "s", position: 2}
],
to_apply: []
}}
Link to this section Summary
Functions
Computes the difference between the original input and a modified string using the PieceTable data structure.
Generates changes between the original input and a modified string using the PieceTable data structure.
Link to this section Types
@type original_input() :: PieceTable.t() | String.t()
Link to this section Functions
@spec diff(original_input(), String.t(), any()) :: {:ok, PieceTable.t()} | {:error, String.t()}
Computes the difference between the original input and a modified string using the PieceTable data structure.
parameters
Parameters
original
(original_input()): The original input string.modified
(String.t()): The modified string.
returns
Returns
{:ok, %PieceTable{}}
: A tuple containing the modified PieceTable structure.{:error, String.t()}
: An error message indicating wrong arguments.
examples
Examples
iex> PieceTable.Differ.diff("test", "text")
{:ok,
%PieceTable{
original: "test",
result: "text",
applied: [
%PieceTable.Change{change: :ins, text: "x", position: 2},
%PieceTable.Change{change: :del, text: "s", position: 2}
],
to_apply: []
}}
iex> PieceTable.Differ.diff("test", 42)
{:error, "Wrong arguments"}
@spec diff!(String.t(), String.t(), any()) :: PieceTable.t()
Generates changes between the original input and a modified string using the PieceTable data structure.
parameters
Parameters
original
(original_input()): The original input string.modified
(String.t()): The modified string.
returns
Returns
%PieceTable{}
: A tuple containing the modified PieceTable structure.
examples
Examples
iex> PieceTable.Differ.diff!("test", "text")
%PieceTable{
original: "test",
result: "text",
applied: [
%PieceTable.Change{change: :ins, text: "x", position: 2},
%PieceTable.Change{change: :del, text: "s", position: 2}
],
to_apply: []
}