Module Odiff

Computing differences.

Representation of differences

type index = Odiff_types.index =
  1. | One of int
    (*

    one line

    *)
  2. | Many of int * int
    (*

    many lines, we have the first and the last

    *)

Index in a file or string.

type diff = Odiff_types.diff =
  1. | Add of index * index * string
    (*

    for <index>a<index> and the added text

    *)
  2. | Delete of index * index * string
    (*

    for <index>d<index> and the deleted text

    *)
  3. | Change of index * string * index * string
    (*

    for <index>c<index> and the deleted and added texts

    *)

Representation of one difference.

type diffs = diff list

Differences between two texts.

Printing differences

val string_of_diff : ?offset:int -> diff -> string

offset is added to line numbers. Default is 0.

val string_of_diffs : ?offset:int -> diffs -> string

offset is added to line numbers. Default is 0.

val print_diffs : Stdlib.out_channel -> ?offset:int -> diffs -> unit

Parsing differences

val from_string : string -> diffs

Return the list of differences from a string generated string.

  • raises Failure

    if an error occurs.

val from_channel : Stdlib.in_channel -> diffs

Same as Odiff.from_string but read from the given in_channel.

val from_file : string -> diffs

Same as Odiff.from_string but read from the given file.

Computing differences

val files_diffs : string -> string -> diffs

files_diffs file1 file2 runs the diff command on the given files and returns its parsed output.

  • raises Failure

    if an error occurs.

val strings_diffs : string -> string -> diffs

Same as Odiff.files_diffs but on strings. The two strings are put in two files to run the diff command. The files are removed before returning the result.

  • raises Failure

    if an error occurs.