diff-lcs 1.6.2 → 2.0.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +85 -34
- data/LICENCE.md +39 -11
- data/Manifest.txt +3 -13
- data/Rakefile +30 -72
- data/SECURITY.md +27 -23
- data/lib/diff/lcs/block.rb +29 -24
- data/lib/diff/lcs/callbacks.rb +240 -242
- data/lib/diff/lcs/change.rb +84 -91
- data/lib/diff/lcs/hunk.rb +92 -155
- data/lib/diff/lcs/internals.rb +92 -96
- data/lib/diff/lcs/ldiff.rb +21 -34
- data/lib/diff/lcs/version.rb +1 -1
- data/lib/diff/lcs.rb +439 -466
- data/licenses/dco.txt +34 -0
- data/spec/hunk_spec.rb +0 -11
- data/spec/lcs_spec.rb +6 -6
- data/spec/ldiff_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -16
- metadata +90 -35
- data/.rspec +0 -1
- data/bin/htmldiff +0 -35
- data/lib/diff/lcs/backports.rb +0 -13
- data/lib/diff/lcs/htmldiff.rb +0 -160
- data/mise.toml +0 -5
- data/spec/fixtures/ldiff/output.diff-e +0 -3
- data/spec/fixtures/ldiff/output.diff-f +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-e +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-f +0 -3
- data/spec/fixtures/ldiff/output.diff.chef2-e +0 -7
- data/spec/fixtures/ldiff/output.diff.chef2-f +0 -7
- /data/{docs → licenses}/COPYING.txt +0 -0
- /data/{docs → licenses}/artistic.txt +0 -0
data/lib/diff/lcs/callbacks.rb
CHANGED
|
@@ -2,109 +2,98 @@
|
|
|
2
2
|
|
|
3
3
|
require "diff/lcs/change"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
class DefaultCallbacks
|
|
15
|
-
class << self
|
|
16
|
-
# Called when two items match.
|
|
17
|
-
def match(event)
|
|
18
|
-
event
|
|
19
|
-
end
|
|
5
|
+
# This callback object implements the default set of callback events, which only returns
|
|
6
|
+
# the event itself.
|
|
7
|
+
#
|
|
8
|
+
# ```ruby
|
|
9
|
+
# Diff::LCS.lcs(seq1, seq2, Diff::LCS::DefaultCallbacks)
|
|
10
|
+
# ```
|
|
11
|
+
class Diff::LCS::DefaultCallbacks
|
|
12
|
+
# Called when two items match.
|
|
13
|
+
def self.match(event) = event
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
event
|
|
24
|
-
end
|
|
15
|
+
# Called when the old value is discarded in favour of the new value.
|
|
16
|
+
def self.discard_a(event) = event
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
event
|
|
29
|
-
end
|
|
18
|
+
# Called when the new value is discarded in favour of the old value.
|
|
19
|
+
def self.discard_b(event) = event
|
|
30
20
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
event
|
|
34
|
-
end
|
|
21
|
+
# Called when both the old and new values have changed.
|
|
22
|
+
def self.change(event) = event
|
|
35
23
|
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# An alias for DefaultCallbacks that is used in
|
|
41
|
-
# Diff::LCS#traverse_sequences.
|
|
42
|
-
#
|
|
43
|
-
# Diff::LCS.LCS(seq1, seq2, Diff::LCS::SequenceCallbacks)
|
|
44
|
-
SequenceCallbacks = DefaultCallbacks
|
|
45
|
-
|
|
46
|
-
# An alias for DefaultCallbacks that is used in
|
|
47
|
-
# Diff::LCS#traverse_balanced.
|
|
48
|
-
#
|
|
49
|
-
# Diff::LCS.LCS(seq1, seq2, Diff::LCS::BalancedCallbacks)
|
|
50
|
-
BalancedCallbacks = DefaultCallbacks
|
|
24
|
+
def self.new = self
|
|
51
25
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
rescue
|
|
55
|
-
callbacks
|
|
26
|
+
class << self
|
|
27
|
+
private :new
|
|
56
28
|
end
|
|
57
29
|
end
|
|
58
30
|
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
31
|
+
# An alias for DefaultCallbacks used in Diff::LCS.traverse_sequences.
|
|
32
|
+
#
|
|
33
|
+
# ```ruby
|
|
34
|
+
# Diff::LCS.lcs(seq1, seq2, Diff::LCS::SequenceCallbacks)
|
|
35
|
+
# ```
|
|
36
|
+
Diff::LCS::SequenceCallbacks = Diff::LCS::DefaultCallbacks
|
|
37
|
+
|
|
38
|
+
# An alias for DefaultCallbacks used in Diff::LCS.traverse_balanced.
|
|
39
|
+
#
|
|
40
|
+
# ```ruby
|
|
41
|
+
# Diff::LCS.lcs(seq1, seq2, Diff::LCS::BalancedCallbacks)
|
|
42
|
+
# ```
|
|
43
|
+
Diff::LCS::BalancedCallbacks = Diff::LCS::DefaultCallbacks
|
|
44
|
+
|
|
45
|
+
# This will produce a compound array of simple diff change objects. Each element in the
|
|
46
|
+
# #diffs array is a `hunk` or `hunk` array, where each element in each `hunk` array is
|
|
47
|
+
# a single Change object representing the addition or removal of a single element from one
|
|
48
|
+
# of the two tested sequences. The `hunk` provides the full context for the changes.
|
|
49
|
+
#
|
|
50
|
+
# ```ruby
|
|
51
|
+
# diffs = Diff::LCS.diff(seq1, seq2)
|
|
52
|
+
# # This example shows a simplified array format.
|
|
53
|
+
# # [ [ [ '-', 0, 'a' ] ], # 1
|
|
54
|
+
# # [ [ '+', 2, 'd' ] ], # 2
|
|
55
|
+
# # [ [ '-', 4, 'h' ], # 3
|
|
56
|
+
# # [ '+', 4, 'f' ] ],
|
|
57
|
+
# # [ [ '+', 6, 'k' ] ], # 4
|
|
58
|
+
# # [ [ '-', 8, 'n' ], # 5
|
|
59
|
+
# # [ '-', 9, 'p' ],
|
|
60
|
+
# # [ '+', 9, 'r' ],
|
|
61
|
+
# # [ '+', 10, 's' ],
|
|
62
|
+
# # [ '+', 11, 't' ] ] ]
|
|
63
|
+
# ```
|
|
64
|
+
#
|
|
65
|
+
# There are five hunks here. The first hunk says that the `a` at position 0 of the first
|
|
66
|
+
# sequence should be deleted (`'-'`). The second hunk says that the `d` at position 2 of
|
|
67
|
+
# the second sequence should be inserted (`'+'`). The third hunk says that the `h` at
|
|
68
|
+
# position 4 of the first sequence should be removed and replaced with the `f` from
|
|
69
|
+
# position 4 of the second sequence. The other two hunks are described similarly.
|
|
70
|
+
#
|
|
71
|
+
# ### Use
|
|
72
|
+
#
|
|
73
|
+
# This callback object must be initialised and is used by the Diff::LCS#diff method.
|
|
74
|
+
#
|
|
75
|
+
# ```ruby
|
|
76
|
+
# cbo = Diff::LCS::DiffCallbacks.new
|
|
77
|
+
# Diff::LCS.lcs(seq1, seq2, cbo)
|
|
78
|
+
# cbo.finish
|
|
79
|
+
# ```
|
|
80
|
+
#
|
|
81
|
+
# Note that the call to #finish is absolutely necessary, or the last set of changes will
|
|
82
|
+
# not be visible. This callback also supports a block mode which automatically calls
|
|
83
|
+
# #finish.
|
|
84
|
+
#
|
|
85
|
+
# ```ruby
|
|
86
|
+
# result = Diff::LCS::DiffCallbacks.new { |cbo| Diff::LCS.lcs(seq1, seq2, cbo) }
|
|
87
|
+
# ```
|
|
88
|
+
#
|
|
89
|
+
# ### Simplified Array Format
|
|
90
|
+
#
|
|
91
|
+
# The simplified array format used in the example above can be obtained with:
|
|
92
|
+
#
|
|
93
|
+
# ```ruby
|
|
94
|
+
# require 'pp'
|
|
95
|
+
# pp diffs.map { |e| e.map { |f| f.to_a } }
|
|
96
|
+
# ```
|
|
108
97
|
class Diff::LCS::DiffCallbacks
|
|
109
98
|
# Returns the difference set collected during the diff process.
|
|
110
99
|
attr_reader :diffs
|
|
@@ -122,15 +111,11 @@ class Diff::LCS::DiffCallbacks
|
|
|
122
111
|
end
|
|
123
112
|
end
|
|
124
113
|
|
|
125
|
-
# Finalizes the diff process. If an unprocessed hunk still exists, then it
|
|
126
|
-
#
|
|
127
|
-
def finish
|
|
128
|
-
finish_hunk
|
|
129
|
-
end
|
|
114
|
+
# Finalizes the diff process. If an unprocessed hunk still exists, then it is appended
|
|
115
|
+
# to the diff list.
|
|
116
|
+
def finish = finish_hunk
|
|
130
117
|
|
|
131
|
-
def match(_event)
|
|
132
|
-
finish_hunk
|
|
133
|
-
end
|
|
118
|
+
def match(_event) = finish_hunk
|
|
134
119
|
|
|
135
120
|
def discard_a(event)
|
|
136
121
|
@hunk << Diff::LCS::Change.new("-", event.old_position, event.old_element)
|
|
@@ -147,81 +132,89 @@ class Diff::LCS::DiffCallbacks
|
|
|
147
132
|
private :finish_hunk
|
|
148
133
|
end
|
|
149
134
|
|
|
150
|
-
# This will produce a compound array of contextual diff change objects. Each
|
|
151
|
-
#
|
|
152
|
-
#
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
#
|
|
160
|
-
#
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
|
-
#
|
|
164
|
-
#
|
|
165
|
-
#
|
|
166
|
-
#
|
|
167
|
-
#
|
|
168
|
-
#
|
|
169
|
-
#
|
|
170
|
-
#
|
|
171
|
-
#
|
|
172
|
-
#
|
|
173
|
-
#
|
|
174
|
-
#
|
|
175
|
-
#
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
# results like:
|
|
179
|
-
#
|
|
180
|
-
#
|
|
181
|
-
#
|
|
182
|
-
#
|
|
183
|
-
#
|
|
184
|
-
#
|
|
185
|
-
#
|
|
186
|
-
#
|
|
187
|
-
#
|
|
188
|
-
#
|
|
189
|
-
#
|
|
190
|
-
#
|
|
191
|
-
#
|
|
192
|
-
#
|
|
193
|
-
#
|
|
194
|
-
#
|
|
195
|
-
#
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
#
|
|
202
|
-
#
|
|
203
|
-
#
|
|
204
|
-
#
|
|
205
|
-
#
|
|
206
|
-
#
|
|
207
|
-
#
|
|
208
|
-
#
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
-
#
|
|
212
|
-
#
|
|
213
|
-
#
|
|
214
|
-
#
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
#
|
|
219
|
-
#
|
|
220
|
-
#
|
|
221
|
-
#
|
|
222
|
-
#
|
|
223
|
-
#
|
|
224
|
-
#
|
|
135
|
+
# This will produce a compound array of contextual diff change objects. Each element in
|
|
136
|
+
# the #diffs array is a "hunk" array, where each element in each "hunk" array is a single
|
|
137
|
+
# change. Each change is a Diff::LCS::ContextChange that contains both the old index and
|
|
138
|
+
# new index values for the change. The "hunk" provides the full context for the changes.
|
|
139
|
+
# Both old and new objects will be presented for changed objects. `nil` will be
|
|
140
|
+
# substituted for a discarded object.
|
|
141
|
+
#
|
|
142
|
+
# ```ruby
|
|
143
|
+
# seq1 = %w(a b c e h j l m n p)
|
|
144
|
+
# seq2 = %w(b c d e f j k l m r s t)
|
|
145
|
+
#
|
|
146
|
+
# diffs = Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
|
|
147
|
+
# # This example shows a simplified array format.
|
|
148
|
+
# # [ [ [ '-', [ 0, 'a' ], [ 0, nil ] ] ], # 1
|
|
149
|
+
# # [ [ '+', [ 3, nil ], [ 2, 'd' ] ] ], # 2
|
|
150
|
+
# # [ [ '-', [ 4, 'h' ], [ 4, nil ] ], # 3
|
|
151
|
+
# # [ '+', [ 5, nil ], [ 4, 'f' ] ] ],
|
|
152
|
+
# # [ [ '+', [ 6, nil ], [ 6, 'k' ] ] ], # 4
|
|
153
|
+
# # [ [ '-', [ 8, 'n' ], [ 9, nil ] ], # 5
|
|
154
|
+
# # [ '+', [ 9, nil ], [ 9, 'r' ] ],
|
|
155
|
+
# # [ '-', [ 9, 'p' ], [ 10, nil ] ],
|
|
156
|
+
# # [ '+', [ 10, nil ], [ 10, 's' ] ],
|
|
157
|
+
# # [ '+', [ 10, nil ], [ 11, 't' ] ] ] ]
|
|
158
|
+
# ```
|
|
159
|
+
#
|
|
160
|
+
# The five hunks shown are comprised of individual changes; if there is a related set of
|
|
161
|
+
# changes, they are still shown individually.
|
|
162
|
+
#
|
|
163
|
+
# This callback can also be used with Diff::LCS#sdiff, which will produce results like:
|
|
164
|
+
#
|
|
165
|
+
# ```ruby
|
|
166
|
+
# diffs = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextCallbacks)
|
|
167
|
+
# # This example shows a simplified array format.
|
|
168
|
+
# # [ [ [ "-", [ 0, "a" ], [ 0, nil ] ] ], # 1
|
|
169
|
+
# # [ [ "+", [ 3, nil ], [ 2, "d" ] ] ], # 2
|
|
170
|
+
# # [ [ "!", [ 4, "h" ], [ 4, "f" ] ] ], # 3
|
|
171
|
+
# # [ [ "+", [ 6, nil ], [ 6, "k" ] ] ], # 4
|
|
172
|
+
# # [ [ "!", [ 8, "n" ], [ 9, "r" ] ], # 5
|
|
173
|
+
# # [ "!", [ 9, "p" ], [ 10, "s" ] ],
|
|
174
|
+
# # [ "+", [ 10, nil ], [ 11, "t" ] ] ] ]
|
|
175
|
+
# ```
|
|
176
|
+
#
|
|
177
|
+
# The five hunks are still present, but are significantly shorter in total presentation,
|
|
178
|
+
# because changed items are shown as changes ("!") instead of potentially "mismatched"
|
|
179
|
+
# pairs of additions and deletions.
|
|
180
|
+
#
|
|
181
|
+
# The result of this operation is similar to that of Diff::LCS::SDiffCallbacks. They may
|
|
182
|
+
# be compared as:
|
|
183
|
+
#
|
|
184
|
+
# ```ruby
|
|
185
|
+
# s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" }
|
|
186
|
+
# c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten(1)
|
|
187
|
+
#
|
|
188
|
+
# s == c # => true
|
|
189
|
+
# ```
|
|
190
|
+
#
|
|
191
|
+
# ### Use
|
|
192
|
+
#
|
|
193
|
+
# This callback object must be initialised and can be used by the Diff::LCS#diff or
|
|
194
|
+
# Diff::LCS#sdiff methods.
|
|
195
|
+
#
|
|
196
|
+
# ```ruby
|
|
197
|
+
# cbo = Diff::LCS::ContextDiffCallbacks.new
|
|
198
|
+
# Diff::LCS.lcs(seq1, seq2, cbo)
|
|
199
|
+
# cbo.finish
|
|
200
|
+
# ```
|
|
201
|
+
#
|
|
202
|
+
# Note that the call to #finish is absolutely necessary, or the last set of changes will
|
|
203
|
+
# not be visible. This callback also supports a block mode which automatically calls
|
|
204
|
+
# #finish.
|
|
205
|
+
#
|
|
206
|
+
# ```ruby
|
|
207
|
+
# result = Diff::LCS::ContextDiffCallbacks.new { |cbo| Diff::LCS.lcs(seq1, seq2, cbo) }
|
|
208
|
+
# ```
|
|
209
|
+
#
|
|
210
|
+
# ### Simplified Array Format
|
|
211
|
+
#
|
|
212
|
+
# The simplified array format used in the example above can be obtained with:
|
|
213
|
+
#
|
|
214
|
+
# ```ruby
|
|
215
|
+
# require 'pp'
|
|
216
|
+
# pp diffs.map { |e| e.map { |f| f.to_a } }
|
|
217
|
+
# ```
|
|
225
218
|
class Diff::LCS::ContextDiffCallbacks < Diff::LCS::DiffCallbacks
|
|
226
219
|
def discard_a(event)
|
|
227
220
|
@hunk << Diff::LCS::ContextChange.simplify(event)
|
|
@@ -236,70 +229,75 @@ class Diff::LCS::ContextDiffCallbacks < Diff::LCS::DiffCallbacks
|
|
|
236
229
|
end
|
|
237
230
|
end
|
|
238
231
|
|
|
239
|
-
# This will produce a simple array of diff change objects. Each element in
|
|
240
|
-
#
|
|
241
|
-
#
|
|
242
|
-
#
|
|
243
|
-
#
|
|
244
|
-
#
|
|
245
|
-
#
|
|
246
|
-
#
|
|
247
|
-
#
|
|
248
|
-
#
|
|
249
|
-
#
|
|
250
|
-
#
|
|
251
|
-
#
|
|
252
|
-
#
|
|
253
|
-
#
|
|
254
|
-
#
|
|
255
|
-
#
|
|
256
|
-
#
|
|
257
|
-
#
|
|
258
|
-
#
|
|
259
|
-
#
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#
|
|
263
|
-
#
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
267
|
-
#
|
|
268
|
-
#
|
|
269
|
-
#
|
|
270
|
-
#
|
|
271
|
-
#
|
|
272
|
-
#
|
|
273
|
-
#
|
|
274
|
-
# The result of this operation is similar to that of
|
|
275
|
-
#
|
|
276
|
-
#
|
|
277
|
-
#
|
|
278
|
-
#
|
|
279
|
-
#
|
|
280
|
-
#
|
|
281
|
-
#
|
|
282
|
-
#
|
|
283
|
-
#
|
|
284
|
-
#
|
|
285
|
-
#
|
|
286
|
-
#
|
|
287
|
-
#
|
|
288
|
-
#
|
|
289
|
-
#
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
#
|
|
293
|
-
#
|
|
294
|
-
#
|
|
295
|
-
#
|
|
296
|
-
#
|
|
297
|
-
#
|
|
298
|
-
#
|
|
299
|
-
#
|
|
300
|
-
#
|
|
301
|
-
#
|
|
302
|
-
#
|
|
232
|
+
# This will produce a simple array of diff change objects. Each element in the #diffs
|
|
233
|
+
# array is a single ContextChange. In the set of #diffs provided by SDiffCallbacks, both
|
|
234
|
+
# old and new objects will be presented for both changed <strong>and unchanged</strong>
|
|
235
|
+
# objects. `nil` will be substituted for a discarded object.
|
|
236
|
+
#
|
|
237
|
+
# The diffset produced by this callback, when provided to Diff::LCS#sdiff, will compute
|
|
238
|
+
# and display the necessary components to show two sequences and their minimized
|
|
239
|
+
# differences side by side, just like the Unix utility `sdiff`.
|
|
240
|
+
#
|
|
241
|
+
# ```ruby
|
|
242
|
+
# # same same
|
|
243
|
+
# # before | after
|
|
244
|
+
# # old < -
|
|
245
|
+
# # - > new
|
|
246
|
+
#
|
|
247
|
+
# seq1 = %w(a b c e h j l m n p)
|
|
248
|
+
# seq2 = %w(b c d e f j k l m r s t)
|
|
249
|
+
#
|
|
250
|
+
# diffs = Diff::LCS.sdiff(seq1, seq2)
|
|
251
|
+
# # This example shows a simplified array format.
|
|
252
|
+
# # [ [ "-", [ 0, "a"], [ 0, nil ] ],
|
|
253
|
+
# # [ "=", [ 1, "b"], [ 0, "b" ] ],
|
|
254
|
+
# # [ "=", [ 2, "c"], [ 1, "c" ] ],
|
|
255
|
+
# # [ "+", [ 3, nil], [ 2, "d" ] ],
|
|
256
|
+
# # [ "=", [ 3, "e"], [ 3, "e" ] ],
|
|
257
|
+
# # [ "!", [ 4, "h"], [ 4, "f" ] ],
|
|
258
|
+
# # [ "=", [ 5, "j"], [ 5, "j" ] ],
|
|
259
|
+
# # [ "+", [ 6, nil], [ 6, "k" ] ],
|
|
260
|
+
# # [ "=", [ 6, "l"], [ 7, "l" ] ],
|
|
261
|
+
# # [ "=", [ 7, "m"], [ 8, "m" ] ],
|
|
262
|
+
# # [ "!", [ 8, "n"], [ 9, "r" ] ],
|
|
263
|
+
# # [ "!", [ 9, "p"], [ 10, "s" ] ],
|
|
264
|
+
# # [ "+", [ 10, nil], [ 11, "t" ] ] ]
|
|
265
|
+
# ```
|
|
266
|
+
#
|
|
267
|
+
# The result of this operation is similar to that of Diff::LCS::ContextDiffCallbacks. They
|
|
268
|
+
# may be compared as:
|
|
269
|
+
#
|
|
270
|
+
# ```ruby
|
|
271
|
+
# s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" }
|
|
272
|
+
# c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten(1)
|
|
273
|
+
#
|
|
274
|
+
# s == c # => true
|
|
275
|
+
# ```
|
|
276
|
+
#
|
|
277
|
+
# ### Use
|
|
278
|
+
#
|
|
279
|
+
# This callback object must be initialised and is used by the Diff::LCS#sdiff method.
|
|
280
|
+
#
|
|
281
|
+
# ```ruby
|
|
282
|
+
# cbo = Diff::LCS::SDiffCallbacks.new
|
|
283
|
+
# Diff::LCS.lcs(seq1, seq2, cbo)
|
|
284
|
+
# ```
|
|
285
|
+
#
|
|
286
|
+
# This callback also supports initialization with a block, but as there is no "finishing"
|
|
287
|
+
# to be done, this has no effect on the state of the object.
|
|
288
|
+
#
|
|
289
|
+
# ```ruby
|
|
290
|
+
# result = Diff::LCS::SDiffCallbacks.new { |cbo| Diff::LCS.lcs(seq1, seq2, cbo) }
|
|
291
|
+
# ```
|
|
292
|
+
#
|
|
293
|
+
# ### Simplified Array Format
|
|
294
|
+
#
|
|
295
|
+
# The simplified array format used in the example above can be obtained with:
|
|
296
|
+
#
|
|
297
|
+
# ```ruby
|
|
298
|
+
# require 'pp'
|
|
299
|
+
# pp diffs.map { |e| e.to_a }
|
|
300
|
+
# ```
|
|
303
301
|
class Diff::LCS::SDiffCallbacks
|
|
304
302
|
# Returns the difference set collected during the diff process.
|
|
305
303
|
attr_reader :diffs
|