'From Cuis 2.0 of 24 February 2010 [latest update: #440] on 1 March 2010 at 10:42:37 am'!

!DifferenceFinder class methodsFor: 'compatibility' stamp: 'jmv 3/1/2010 10:42'!
wordsDisplayPatchFrom: srcString to: dstString
	| finder answer src1 dst1 changedCount |
	finder _ self base: srcString case: dstString.
	finder compareLines; compute.

	answer _ '' asText.
	src1 _ '' writeStream.
	dst1 _ '' writeStream.
	changedCount _ 0.
	finder differences sort first do: [:item :condition |
		condition caseOf: {
			[ #unchanged ] -> [
				changedCount > 0 ifTrue: [
					"If the sequence of changed lines is large, comparing words gets too slow and less useful"
					changedCount > 10 ifTrue: [
						^nil ].
					"Compare the just ended sequence of changed lines"
					finder base: src1 contents case: dst1 contents.
					finder compareWords; compute.
					answer _ answer append:  finder differences anyOne asText.
					src1 resetToStart.
					dst1 resetToStart.
					changedCount _ 0.
				].
				"This line hasn't changed. Just add it to the result in plain text."
				answer append: item ].
			[ #removed ] -> [
				"A removed line belongs in the source"
				src1 nextPutAll: item.
				changedCount _ changedCount + 1 ].
			[ #inserted ] -> [
				"An added line belongs in the destination"
				dst1 nextPutAll: item.
				changedCount _ changedCount + 1  ].
			}.
		].

	"If the sequence of changed lines is large, comparing words gets too slow and less useful"
	changedCount > 10 ifTrue: [
		^nil ].
					
	finder base: src1 contents case: dst1 contents.
	finder compareWords; compute.
	answer append:  finder differences anyOne asText.

	^answer! !

