Leon
Leon

Reputation: 339

diff_match_patch google library is not working as expected in C#

I am writing the text change tracking add-in and my code is:

   mDiffMatchPatch = new diff_match_patch()
   List<Diff> diffList = mDiffMatchPatch.diff_main(OriginalText, ModifiedText);                        
   mDiffMatchPatch.diff_cleanupSemantic(diffList);

Where Diff is an object with two properties, 'text' and 'operation'

My original text is :

enter image description here

When I just insert the word 'ice' after 'installer' is shows up as it should: enter image description here

But when I highlight 'installer' and type 'ice' on top of it (replacing 'installer' by 'ice' in one operation), it shows incorrectly. enter image description here

That is, it takes the first letter of original 'installer' and separates 'i' from 'ce' in 'ice'.

I checked and re-rechecked and my text color rendering is correct. It is the diff_match_match breaks the 'i' from 'ice' in order to match it with the 'i' of 'installer'.

Is there any remedy for this? If not, is there alternative libraries in C# for diff_match_patch?

M

Upvotes: 0

Views: 581

Answers (1)

Leon
Leon

Reputation: 339

I resolved it by following the guidance on project github page. That is, using the word-based diff function of the diff_match_patch object. You create it by copying line-based function and modifying it per article.

Upvotes: 0

Related Questions