Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.
/ difflib Public archive

Kotlin implementation of Python difflib

License

Notifications You must be signed in to change notification settings

mhv2109/difflib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Packages

No packages published