Dmitry Savenko

Software Engineer. Get in touch:

Project: Diff

14 Jul 2011

Diff is a Fantom library to find differences between two sequences of objects of any type (e.g. strings, text files line-by-line, etc). As a pure Fantom library, it can be compiled into Java or JavaScript.

Based on the C# library by Matthias Hertel.


Find differences between simple strings:

using diff

class DiffExample
  static Void main(Str[] args) {
    echo("*** Strings from wiki page ( ***")
    sa := "abcdfghjqz"
    sb := "abcdefgijkrxyz"
    echo("String A: $sa")
    echo("String B: $sb")
    echo(, sb))
    echo("\n*** List of numbers ***")
    la := [1, 2, 3, 4]
    lb := [3, 4, 1, 2]
    echo("List A: $la")
    echo("List B: $lb")
    echo(, lb))
    echo("\n*** Example, when setting minimal flag results in shorter deltas ***")
    echo("  (setting minimal flag may decrease performance dramatically)")
    ma := "aa"
    mb := "ba"
    echo("String A: $ma")
    echo("String B: $mb")
    echo("Without minimal flag set: " +, mb))
    echo("With minimal flag set: " +, mb, true))

File differences between text files:

using diff

class FileExample
  static Void main(Str[] args) {
    if (2 > args.size) {
      echo("Compares two files line by line")
      echo("Usage: fan <file A> <file B>")
    inA := File(`${args[0]}`).in
    inB := File(`${args[1]}`).in
    deltas :=, inB)
    deltas.each { echo("$it.a => $it.b") }