Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
mhv2109Public archive

About

Kotlin implementation of Python difflib

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

Repository files navigation

Difflib

This is a Kotlin port of the difflib Python package found here. Requires JRE >= 8.

Features

SequenceMatcher

A flexible class for comparing pairs of sequences. The basic algorithm predates, and is a little fancier than, an algorithm published in the late 1980's by Ratcliff and Obershelp under the hyperbolic name "gestalt pattern matching".

val s = SequenceMatcher("abcd".toList(), "bcde".toList())
s.ratio() // 0.75

Differ

Differ is a class for comparing sequences of lines of text, and producing human-readable differences or deltas.

val d = Differ()
val a = listOf("one\n", "two\n", "three\n")
val b = listOf("ore\n", "tree\n", "emu\n")
d.compare(a, b)

HtmlDiff

Note: This class depends on experimental Kotlin features!

For producing HTML side by side comparison with change highlights. The current implementation differs from the original Python difflib.HtmlDiff in that it uses SequenceMatcher to produce side-by-side comparisons instead of Differ.

val from = listOf("one", "two", "three")
val to = listOf("once", "too", "tree")
htmlDiff.makeFile(from, to)

Usage

Gradle

repositories {
    jcenter() 
}
...
dependencies {
    compile 'com.mhv2109:difflib:1.0.0'
}

Maven

<repositories>
    <repository>
      <id>jcenter<id>
      <url>https://jcenter.bintray.com/</url>
    </repository>
</repositories>
...
<dependency>
  <groupId>com.mhv2109</groupId>
  <artifactId>difflib</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

About

Kotlin implementation of Python difflib

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages