@@ -22,11 +22,9 @@ package io.github.petertrr.diffutils
22
22
23
23
import io.github.petertrr.diffutils.algorithm.DiffAlgorithm
24
24
import io.github.petertrr.diffutils.algorithm.DiffAlgorithmListener
25
- import io.github.petertrr.diffutils.algorithm.DiffEqualizer
26
25
import io.github.petertrr.diffutils.algorithm.NoopAlgorithmListener
27
26
import io.github.petertrr.diffutils.algorithm.myers.MyersDiff
28
27
import io.github.petertrr.diffutils.patch.Patch
29
- import io.github.petertrr.diffutils.patch.PatchFailedException
30
28
import io.github.petertrr.diffutils.text.DiffRowGenerator
31
29
import kotlin.jvm.JvmName
32
30
import kotlin.jvm.JvmOverloads
@@ -35,16 +33,16 @@ import kotlin.jvm.JvmOverloads
35
33
private val lineBreak = Regex (" \r\n |\r |\n " )
36
34
37
35
/* *
38
- * Computes the difference between the source and target text .
36
+ * Computes the difference between two strings .
39
37
*
40
38
* By default, uses the Myers algorithm.
41
39
*
42
- * @param sourceText The original text
43
- * @param targetText The target text
40
+ * @param sourceText A string representing the original text
41
+ * @param targetText A string representing the revised text
44
42
* @param algorithm The diff algorithm to use
45
43
* @param progress The diff algorithm progress listener
46
44
* @param includeEqualParts Whether to include equal data parts into the patch. `false` by default.
47
- * @return The patch describing the difference between the original and target text
45
+ * @return The patch describing the difference between the original and revised strings
48
46
*/
49
47
@JvmOverloads
50
48
public fun diff (
@@ -65,14 +63,14 @@ public fun diff(
65
63
/* *
66
64
* Computes the difference between the original and target list of elements.
67
65
*
68
- * By default, uses the Meyers algorithm.
66
+ * By default, uses the Myers algorithm.
69
67
*
70
- * @param source The original elements
71
- * @param target The target elements
68
+ * @param source A list representing the original sequence of elements
69
+ * @param target A list representing the revised sequence of elements
72
70
* @param algorithm The diff algorithm to use
73
71
* @param progress The diff algorithm progress listener
74
- * @param includeEqualParts Whether to include equal data parts into the patch. `false` by default.
75
- * @return The patch describing the difference between the original and target sequences
72
+ * @param includeEqualParts Whether to include equal parts in the resulting patch. `false` by default.
73
+ * @return The patch describing the difference between the original and revised sequences
76
74
*/
77
75
@JvmOverloads
78
76
public fun <T > diff (
@@ -94,6 +92,10 @@ public fun <T> diff(
94
92
*
95
93
* This one uses the "trick" to make out of texts lists of characters,
96
94
* like [DiffRowGenerator] does and merges those changes at the end together again.
95
+ *
96
+ * @param original A string representing the original text
97
+ * @param revised A string representing the revised text
98
+ * @return The patch describing the difference between the original and revised text
97
99
*/
98
100
public fun diffInline (original : String , revised : String ): Patch <String > {
99
101
val origChars = original.toCharArray()
@@ -122,22 +124,21 @@ public fun diffInline(original: String, revised: String): Patch<String> {
122
124
}
123
125
124
126
/* *
125
- * Patch the original text with the given patch .
127
+ * Applies the given patch to the original list and returns the revised list .
126
128
*
127
- * @param original The original text
129
+ * @param original A list representing the original sequence of elements
128
130
* @param patch The patch to apply
129
- * @return The revised text
130
- * @throws PatchFailedException If the patch cannot be applied
131
+ * @return A list representing the revised sequence of elements
131
132
*/
132
133
public fun <T > patch (original : List <T >, patch : Patch <T >): List <T > =
133
134
patch.applyTo(original)
134
135
135
136
/* *
136
- * Unpatch the revised text for a given patch
137
+ * Applies the given patch to the revised list and returns the original list.
137
138
*
138
- * @param revised The revised text
139
- * @param patch The given patch
140
- * @return The original text
139
+ * @param revised A list representing the revised sequence of elements
140
+ * @param patch The patch to apply
141
+ * @return A list representing the original sequence of elements
141
142
*/
142
143
public fun <T > unpatch (revised : List <T >, patch : Patch <T >): List <T > =
143
144
patch.restore(revised)
0 commit comments