Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xIndex for instertion after location #101

Open
GoogleCodeExporter opened this issue May 6, 2015 · 0 comments
Open

xIndex for instertion after location #101

GoogleCodeExporter opened this issue May 6, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

Hello!

When you are looking for the end position while something was added to the end 
of the text, then result will be the end of the new text. Here is a test:
    assertEquals(3, dmp.diff_xIndex([[DIFF_EQUAL, 'foo'], [DIFF_INSERT, 'bar']], 3));
The result will be 6.

My understanding of locations within text is that it's just like a cursor. For 
example:
    |foo - position 0
    f|oo - position 1
    fo|o - position 2
    foo| - position 3

I've tried to fix it by myself and have changed > comparison to >= in 
https://code.google.com/p/google-diff-match-patch/source/browse/trunk/javascript
/diff_match_patch_uncompressed.js#1199
but it's actually breaks the last test for patchApply, so I'm doubting about my 
understanding of locations within text. So, can you make it clear what is that 
location in xIndex method?

By the way, there is a small bug in the doc example for xIndex:
    e.g. 'The cat' vs 'The big cat', 1->1, 5->8
There was 4 chars inserted ("big "), so 5 should became 9.

Original issue reported on code.google.com by grigory.kalabin on 29 Apr 2014 at 3:05

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant