[resend, picky postmaster refused the message]
> I am attaching some examples to describe the return value of this function.
>
> Example 1:
> ---------- old text -----------
> aaaaaa
> aaaaaa
> aaaaaa
> --------------------------------
>
> ---------- new text -----------
> aaaxx
> xxxxxx
> xxaaa
> ----------------------------------
>
> The modification starts at index 0 and byte 3 and ends at index 2 byte 2 in
> the
> old text. In the new text, the changes start at index 0 byte 3 and end at
> index
> 2 byte 1. In this case, the diff() function returns the following:
>
> [{'from': {'start': {'idx': 0, 'byte': 3}, 'end': {'idx': 2, 'byte': 2}},
> 'to': {'start': {'idx': 0, 'byte': 3}, 'end': {'idx': 2, 'byte': 1}}}]
So, how does one decide whether items were inserted or removed?
I think that's by computing the size in items of "from" and doing the
same for "to" and then they turn out to be equal. If someone cares
about items being inserted/deleted this is a bit of an indirect way to
find out.
> Example 2:
> ---------- old text -----------
> aaaaaa
> bbbbbb
> cccccc
> --------------------------------
>
> ---------- new text -----------
> aaaaaa
> ----------------------------------
>
> In the old text, the modification starts at index 1 byte 0 and ends at
> index 2 byte 5.
> In the new text, the modification starts at index 1. But the byte cannot
> be calculated
> as the line is removed. Similarly the end of the modification also cannot
> be calculated.
> In this case, the diff() function returns the following:
>
> [{'from': {'start': {'idx': 1, 'byte': 0}, 'end': {'idx': 2, 'byte': 5}},
> 'to': {'start': {'idx': 1, 'byte': -1}, 'end': {'idx': -1, 'byte': -1}}}]
Now how does one compute the number of items inserted/removed? Is it
true that when "to" has an "end" with index -1, that there are no items
at all? Not sure that is always true.
> Example 3:
> ---------- old text -----------
> aaaaaa
> --------------------------------
>
> ---------- new text -----------
> aaaaaa
> bbbbbb
> cccccc
> ----------------------------------
>
> In the old text, the modification starts at index 1. But the starting byte
> and ending index/byte
> cannot be calculated. In the new text, the change starts at index 1 byte 0
> and ends at
> index 2 byte 5. In this case, the diff() function returns the following:
>
> [{'from': {'start': {'idx': 1, 'byte': -1}, 'end': {'idx': -1, 'byte': -1}},
> 'to': {'start': {'idx': 1, 'byte': 0}, 'end': {'idx': 2, 'byte': 5}}}]
So the "from" position indicates "end of the list". And the "to" info
has two items, thus two items have been added.
I hope you see that, depending on what the user of the function wants to
know, the returned value can be hard to understand.
--
BEDEVERE: And that, my lord, is how we know the Earth to be banana-shaped.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20230502233906.E294D1C123B%40moolenaar.net.