18
18
*/
19
19
package io.github.petertrr.diffutils.text
20
20
21
- import io.github.petertrr.diffutils.algorithm.DiffEqualizer
21
+ import io.github.petertrr.diffutils.algorithm.DiffAlgorithm
22
22
import io.github.petertrr.diffutils.algorithm.EqualsDiffEqualizer
23
23
import io.github.petertrr.diffutils.algorithm.IgnoreWsStringDiffEqualizer
24
+ import io.github.petertrr.diffutils.algorithm.myers.MyersDiff
24
25
import io.github.petertrr.diffutils.diff
25
26
import io.github.petertrr.diffutils.patch.ChangeDelta
26
27
import io.github.petertrr.diffutils.patch.Chunk
@@ -42,7 +43,7 @@ import kotlin.math.min
42
43
* @param columnWidth Set the column width of generated lines of original and revised texts.
43
44
* Making it < 0 doesn't make any sense.
44
45
* @param ignoreWhiteSpaces Ignore white spaces in generating diff rows or not
45
- * @param equalizer Provide an equalizer for diff processing
46
+ * @param algorithm The diffing algorithm to use. By default [MyersDiff].
46
47
* @param inlineDiffByWord Per default each character is separately processed.
47
48
* Setting this parameter to `true` introduces processing by word, which does
48
49
* not deliver in word changes. Therefore, the whole word will be tagged as changed:
@@ -80,9 +81,9 @@ import kotlin.math.min
80
81
public class DiffRowGenerator (
81
82
private val columnWidth : Int = 80 ,
82
83
private val ignoreWhiteSpaces : Boolean = false ,
83
- private var equalizer : DiffEqualizer <String > = if (ignoreWhiteSpaces) IgnoreWsStringDiffEqualizer () else EqualsDiffEqualizer ( ),
84
+ private val algorithm : DiffAlgorithm <String > = defaultAlgorithm (ignoreWhiteSpaces),
84
85
inlineDiffByWord : Boolean = false ,
85
- private val inlineDiffSplitter : DiffSplitter = if (inlineDiffByWord) WordDiffSplitter () else CharDiffSplitter ( ),
86
+ private val inlineDiffSplitter : DiffSplitter = defaultSplitter (inlineDiffByWord),
86
87
private val mergeOriginalRevised : Boolean = false ,
87
88
private val newTag : DiffTagGenerator = HtmlDiffTagGenerator ("editNewInline"),
88
89
private val oldTag : DiffTagGenerator = HtmlDiffTagGenerator ("editOldInline"),
@@ -102,7 +103,7 @@ public class DiffRowGenerator(
102
103
* @return The [DiffRow]s between original and revised texts
103
104
*/
104
105
public fun generateDiffRows (original : List <String >, revised : List <String >): List <DiffRow > =
105
- generateDiffRows(original, diff(original, revised, equalizer ))
106
+ generateDiffRows(original, diff(original, revised, algorithm ))
106
107
107
108
/* *
108
109
* Generates the [DiffRow]s describing the difference between original and
@@ -278,7 +279,7 @@ public class DiffRowGenerator(
278
279
val origList = inlineDiffSplitter.split(joinedOrig)
279
280
val revList = inlineDiffSplitter.split(joinedRev)
280
281
281
- val diff = diff(origList, revList, equalizer )
282
+ val diff = diff(origList, revList, algorithm )
282
283
val inlineDeltas = diff.deltas.reversed()
283
284
284
285
for (inlineDelta in inlineDeltas) {
@@ -470,3 +471,11 @@ public class DiffRowGenerator(
470
471
return sequence
471
472
}
472
473
}
474
+
475
+ private fun defaultAlgorithm (ignoreWhiteSpaces : Boolean ): DiffAlgorithm <String > {
476
+ val equalizer = if (ignoreWhiteSpaces) IgnoreWsStringDiffEqualizer () else EqualsDiffEqualizer ()
477
+ return MyersDiff (equalizer)
478
+ }
479
+
480
+ private fun defaultSplitter (inlineDiffByWord : Boolean ): DiffSplitter =
481
+ if (inlineDiffByWord) WordDiffSplitter () else CharDiffSplitter ()
0 commit comments