
Efficiently computes text and sequence diffs using Myers and linear-space variants; simple DSL and builder-based extensibility, generates/applies patches, zero external dependencies, well-tested.
A Kotlin Multiplatform (KMP) library for computing text diffs, supporting multiple algorithms including Myers and Myers with linear space optimization. Designed for JVM, Android, iOS, and other Kotlin targets. No additional dependencies required.
This library is a Kotlin port of java-diff-utils.
Add the following to your build.gradle.kts:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.baole:diff-kotlin:<latest-version>")
}Replace <latest-version> with the version published on Maven Central.
import io.github.diff.generatePatch
import io.github.diff.Delta
val patch = generatePatch {
this.original = listOf("line1", "line2", "line3", "line4", "line5")
this.revised = listOf("line1", "line3", "line4 modified", "line5", "line6")
}
for (delta: Delta<String> in patch.getDeltas()) {
println(delta)
}import io.github.diff.PatchFailedException
import io.github.diff.patch
try {
val result = patch.patch(original)
println(result.joinToString("\n"))
} catch (e: PatchFailedException) {
e.printStackTrace()
}You can select the algorithm when generating patches.
This project uses:
Run code quality checks:
./gradlew ktlintCheckAuto-fix formatting issues:
./gradlew ktlintFormatContributions are welcome! Please open issues or submit pull requests.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
A Kotlin Multiplatform (KMP) library for computing text diffs, supporting multiple algorithms including Myers and Myers with linear space optimization. Designed for JVM, Android, iOS, and other Kotlin targets. No additional dependencies required.
This library is a Kotlin port of java-diff-utils.
Add the following to your build.gradle.kts:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.baole:diff-kotlin:<latest-version>")
}Replace <latest-version> with the version published on Maven Central.
import io.github.diff.generatePatch
import io.github.diff.Delta
val patch = generatePatch {
this.original = listOf("line1", "line2", "line3", "line4", "line5")
this.revised = listOf("line1", "line3", "line4 modified", "line5", "line6")
}
for (delta: Delta<String> in patch.getDeltas()) {
println(delta)
}import io.github.diff.PatchFailedException
import io.github.diff.patch
try {
val result = patch.patch(original)
println(result.joinToString("\n"))
} catch (e: PatchFailedException) {
e.printStackTrace()
}You can select the algorithm when generating patches.
This project uses:
Run code quality checks:
./gradlew ktlintCheckAuto-fix formatting issues:
./gradlew ktlintFormatContributions are welcome! Please open issues or submit pull requests.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.