162 ! ! |
162 ! ! |
163 |
163 |
164 !DiffCodeView2 methodsFor:'private'! |
164 !DiffCodeView2 methodsFor:'private'! |
165 |
165 |
166 computeDiffDataForText1:t1 text2:t2 |
166 computeDiffDataForText1:t1 text2:t2 |
|
167 "created diffText object from two strings |
|
168 This processes the DiffData as returned by the (now internal) Diff-tool" |
|
169 |
|
170 "/ cg: same code as in Diff2CodeView2!!!!!! |
|
171 "/ please refactor and make this a utility method on the class side |
|
172 |
|
173 |array1 array2 diff change index1 index2 text1 text2 i |
|
174 diffData deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom |
|
175 array1Size array2Size cr| |
|
176 |
|
177 cr := Character cr asString. |
|
178 |
|
179 "create line arrays from origin text(1 item/row)" |
|
180 array1 := self createArray:t1. |
|
181 array2 := self createArray:t2. |
|
182 "inserted,deleted, cahnged lines" |
|
183 inserted := OrderedCollection new. |
|
184 deleted := OrderedCollection new. |
|
185 changed := OrderedCollection new. |
|
186 "indicates which row of origin text is added to ne text" |
|
187 index1 := 1. |
|
188 index2 := 1. |
|
189 "indicate how much rows were deleted or inserted " |
|
190 addConstant1 := 0. |
|
191 addConstant2 := 0. |
|
192 text1 := OrderedCollection new. |
|
193 text2 := OrderedCollection new. |
|
194 diff := Diff new. |
|
195 diff a:array1 b:array2. |
|
196 change := diff diff:false. |
|
197 diffData := DiffData new. |
|
198 [ change notNil ] whileTrue:[ |
|
199 "check first lines which are same" |
|
200 (((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[ |
|
201 [ |
|
202 index1 <= (change line0) |
|
203 ] whileTrue:[ |
|
204 helperText := (array1 at:index1) asText. |
|
205 text1 add: helperText asString. |
|
206 index1 := index1 + 1. |
|
207 ]. |
|
208 [ |
|
209 index2 <= (change line1) |
|
210 ] whileTrue:[ |
|
211 helperText := (array2 at:index2) asText. |
|
212 text2 add: helperText. |
|
213 index2 := index2 + 1. |
|
214 ]. |
|
215 ]. |
|
216 ins := change inserted. |
|
217 del := change deleted. |
|
218 index1 := (change line0) + 1. |
|
219 index2 := (change line1) + 1. |
|
220 "find replaced lines " |
|
221 ((del > 0) and:[ ins > 0 ]) ifTrue:[ |
|
222 helper := del - ins. |
|
223 (helper <= 0) ifTrue:[ |
|
224 pom := change deleted. |
|
225 ]. |
|
226 (helper > 0) ifTrue:[ |
|
227 pom := change inserted. |
|
228 ]. |
|
229 "its same count row" |
|
230 i := 1. |
|
231 [ i <= pom ] whileTrue:[ |
|
232 changed add:index1 + addConstant1. |
|
233 text1 add: (array1 at:index1) asString. |
|
234 text2 add: (array2 at:index2) asString. |
|
235 index1 := index1 + 1. |
|
236 index2 := index2 + 1. |
|
237 del := del - 1. |
|
238 ins := ins - 1. |
|
239 i := i + 1. |
|
240 ]. |
|
241 ]. |
|
242 "find deleted lines" |
|
243 (del > 0) ifTrue:[ |
|
244 i := 1. |
|
245 [ i <= del ] whileTrue:[ |
|
246 deleted add:index1 + addConstant1. |
|
247 text2 add: cr. |
|
248 addConstant2 := addConstant2 + 1. |
|
249 text1 add: (array1 at:index1) asString. |
|
250 index1 := index1 + 1. |
|
251 i := i + 1. |
|
252 ]. |
|
253 ]. |
|
254 "find inserted lines" |
|
255 (ins > 0) ifTrue:[ |
|
256 i := 1. |
|
257 [ i <= ins ] whileTrue:[ |
|
258 inserted add:index2 + addConstant2. |
|
259 text1 add: cr. |
|
260 addConstant1 := addConstant1 + 1. |
|
261 text2 add: (array2 at:index2) asString. |
|
262 index2 := index2 + 1. |
|
263 i := i + 1. |
|
264 ]. |
|
265 ]. |
|
266 change := change nextLink. |
|
267 ]. |
|
268 "kontrola zda nam nechybi posledni znaky" |
|
269 array1Size := array1 size. |
|
270 (index1 <= array1Size) ifTrue:[ |
|
271 [ index1 <= array1Size ] whileTrue:[ |
|
272 helperText := (array1 at:index1) asText. |
|
273 text1 add: helperText. |
|
274 index1 := index1 + 1. |
|
275 ]. |
|
276 ]. |
|
277 array2Size := array2 size. |
|
278 (index2 <= array2Size) ifTrue:[ |
|
279 [ index2 <= array2Size ] whileTrue:[ |
|
280 helperText := (array2 at:index2) asText. |
|
281 text2 add: helperText. |
|
282 index2 := index2 + 1. |
|
283 ]. |
|
284 ]. |
|
285 |
|
286 1 to:(text1 size min:text2 size) do:[:idx | |
|
287 |l1 l2| |
|
288 |
|
289 l1 := text1 at:idx. |
|
290 l2 := text2 at:idx. |
|
291 l1 = l2 ifTrue:[ |
|
292 text1 at:idx put:l1 string. "/ remove color |
|
293 text2 at:idx put:l2 string. |
|
294 changed remove:idx ifAbsent:[]. |
|
295 ] ifFalse:[ |
|
296 l1 withoutSeparators = l2 withoutSeparators ifTrue:[ |
|
297 text1 at:idx put:l1 string. "/ remove color |
|
298 text2 at:idx put:l2 string. |
|
299 changed remove:idx ifAbsent:[]. |
|
300 ] ifFalse:[ |
|
301 "/ self halt. |
|
302 ] |
|
303 ] |
|
304 ]. |
|
305 |
|
306 diffData text1:(text1 asStringWith:''). |
|
307 diffData text2:(text2 asStringWith:''). |
|
308 diffData changed:changed. |
|
309 diffData inserted:inserted. |
|
310 diffData deleted:deleted. |
|
311 ^ diffData. |
|
312 |
|
313 "Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>" |
|
314 "Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
315 "Modified: / 17-07-2012 / 18:55:01 / cg" |
|
316 ! |
|
317 |
|
318 createArray:text1 |
|
319 "cg: isn't that an obfuscated variation of #asCollectionOfLines ?" |
|
320 |
|
321 "/ ^ text1 asStringCollection. "/ yes, it looks like !! |
|
322 |
|
323 "/ JV@2012-07-26: Yes, looks like but it is not!! This version |
|
324 "/ keeps CRs in lines. Do not change it back - if you do, DoffCodeView2 |
|
325 "/ will show whole source in a single line. |
|
326 |
|
327 | array src line c | |
|
328 |
|
329 array := StringCollection new. |
|
330 src := text1 readStream. |
|
331 line := (String new: 80) writeStream. |
|
332 [ src atEnd ] whileFalse:[ |
|
333 c := src next. |
|
334 line nextPut: c. |
|
335 c == Character cr ifTrue:[ |
|
336 array add: line contents. |
|
337 line reset. |
|
338 ] |
|
339 ]. |
|
340 line position ~~ 0 ifTrue:[ |
|
341 array add: line contents |
|
342 ]. |
|
343 ^array |
|
344 |
|
345 "Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>" |
|
346 "Modified: / 17-07-2012 / 18:55:21 / cg" |
|
347 "Modified (comment): / 26-07-2012 / 21:45:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
348 ! |
|
349 |
|
350 old_computeDiffDataForText1:t1 text2:t2 |
167 "created diffText object from two strings |
351 "created diffText object from two strings |
168 This processes the DiffData as returned by the (now internal) Diff-tool" |
352 This processes the DiffData as returned by the (now internal) Diff-tool" |
169 |
353 |
170 "/ cg: same code as in Diff2CodeView2!!!!!! |
354 "/ cg: same code as in Diff2CodeView2!!!!!! |
171 "/ please refactor and make this a utility method on the class side |
355 "/ please refactor and make this a utility method on the class side |
288 ^ diffData. |
472 ^ diffData. |
289 |
473 |
290 "Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>" |
474 "Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>" |
291 "Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
475 "Modified: / 24-06-2010 / 21:07:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
292 "Modified: / 17-07-2012 / 18:55:01 / cg" |
476 "Modified: / 17-07-2012 / 18:55:01 / cg" |
293 ! |
|
294 |
|
295 createArray:text1 |
|
296 "cg: isn't that an obfuscated variation of #asCollectionOfLines ?" |
|
297 |
|
298 "/ ^ text1 asStringCollection. "/ yes, it looks like !! |
|
299 |
|
300 "/ JV@2012-07-26: Yes, looks like but it is not!! This version |
|
301 "/ keeps CRs in lines. Do not change it back - if you do, DoffCodeView2 |
|
302 "/ will show whole source in a single line. |
|
303 |
|
304 | array src line c | |
|
305 |
|
306 array := StringCollection new. |
|
307 src := text1 readStream. |
|
308 line := (String new: 80) writeStream. |
|
309 [ src atEnd ] whileFalse:[ |
|
310 c := src next. |
|
311 line nextPut: c. |
|
312 c == Character cr ifTrue:[ |
|
313 array add: line contents. |
|
314 line reset. |
|
315 ] |
|
316 ]. |
|
317 line position ~~ 0 ifTrue:[ |
|
318 array add: line contents |
|
319 ]. |
|
320 ^array |
|
321 |
|
322 "Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>" |
|
323 "Modified: / 17-07-2012 / 18:55:21 / cg" |
|
324 "Modified (comment): / 26-07-2012 / 21:45:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
325 ! ! |
477 ! ! |
326 |
478 |
327 !DiffCodeView2::DiffData methodsFor:'accessing'! |
479 !DiffCodeView2::DiffData methodsFor:'accessing'! |
328 |
480 |
329 changed |
481 changed |