qtrac.ddiff

* This module implements the Python difflib module's sequence matcher and * provides a diff() function. * * The function takes two slicable forward ranges of < and == comparable * objects (e.g., two slices of strings, two strings, two slices of ints, * two slices of "items") and diffs them using a slightly simplified * version of the Python difflib's sequence matcher algorithm. The * function returns a (possibly empty) slice of Diff structs, each with a * tag (equal, insert, delete, replace) and the two relevant subslices. * * See tests.d for some examples including Test #17, #18 and #19. * * Authors: Mark Summerfield, mark@qtrac.eu * License: Apache 2.0 * Copyright: © 2020 Mark Summerfield. All rights reserved.

Members

Enums

EqualSpan
enum EqualSpan

* Used to tell the diff() function whether to include Diff structs in * its output slice that have all possible tags, including the Equal tag * (Keep), or only difference tags, Insert, Delete, Replace (Drop).

Tag
enum Tag

* What kind of difference the Diff struct represents.

Functions

diff
auto diff(R a, R b, EqualSpan equalSpan)

* Iterates two slices and diffs them. * Params: * a = a forward sliceable range * b = a forward sliceable range * equalSpan = an EqualSpan * Elements from a and b must be comparable for equality. * If equalSpan is Drop (the default), then only Diff structs with Insert, * Delete, or Replace tags will be returned; otherwise Diff structs * covering all the input will be returned, so will additionally include * Diff structs with Equal tags. * Returns: A slice of Diff structs.

Structs

Diff
struct Diff(E)

* A difference with a tag to specify what the difference is and the two * relevant subslices.

Meta