All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.appmetrica.gradle.aarcheck.utils.DiffUtils.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-beta+94
Show newest version
package io.appmetrica.gradle.aarcheck.utils

import com.github.difflib.DiffUtils
import com.github.difflib.UnifiedDiffUtils

object DiffUtils {
    private const val DIFF_CONTEXT_SIZE = 3

    fun diff(
        original: String,
        revised: String,
        originalName: String = "original",
        revisedName: String = "revised"
    ): String? {
        val originalLines = original.lines()
        val revisedLines = revised.lines()
        val diff = DiffUtils.diff(originalLines, revisedLines)
        return if (diff.deltas.isNotEmpty()) {
            val diffStr = UnifiedDiffUtils.generateUnifiedDiff(
                originalName,
                revisedName,
                originalLines,
                diff,
                DIFF_CONTEXT_SIZE
            )
            diffStr.joinToString("\n")
        } else {
            null
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy