You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
const text1="this\n is\n a\n test\n";
const text2="this\n wasn't\n a\n test\n";
// Example code "as is":
var dmp = new diff_match_patch();
var a = dmp.diff_linesToChars_(text1, text2);
var lineText1 = a[0];
var lineText2 = a[1];
var lineArray = a[2];
var diffs = dmp.diff_main(lineText1, lineText2, false);
dmp.diff_charsToLines_(diffs, lineArray);
Causes this exception:
Uncaught Error: Null input. (diff_main)
at diff_match_patch.diff_main (:2:190)
at :6:19
Thank you for the swift response, if you're editing the docs - you might want to use more explicit variable name than a.
For example:
function diff_lineMode(text1, text2) {
var dmp = new diff_match_patch();
var lineMode = dmp.diff_linesToChars_(text1, text2);
var diffs = dmp.diff_main(lineMode.chars1, lineMode.chars2, false);
dmp.diff_charsToLines_(diffs, lineMode.lineArray);
return diffs;
}
Also, why is diff_linesToWords a part of the docs and not a part of the library itself ?
Your suggestion is optimal for JavaScript and Java where an object is returned, but in other languages such as Python the return value is an array. So I think the code on the wiki is a good compromise, that makes it relatively easy for people to translate the example into the language they are using.
The reason diff_linesToWords is not part of the library is that nobody can agree on the definition of a word. I developed the word count for Google Docs, and learned that it's a fairly arbitrary number. Open Office, MS Word, and Google Docs all report significantly different word counts for the same non-trivial document. For example, is "coca-cola.com" one or two or three words? And then there's the nightmare of what to do about CJK languages. If I were to add a word-splitting algorithm to diff-match-patch, I'd end up dealing with conflicting bug reports for the rest of my life. :)
Got your note a regarding the word-splitting, didn't think about that.
However, regarding the return type of diff_linesToChars_, I am not a master in lua or dart, but in python, its super simple.
Just wrap the return value with a namedtuple.
This will allow your users to access the object as an array or by its attributes - backward compatible, and it works for python2 and python3.
See example:
from collections import namedtuple
LineModeObj = namedtuple("LineModeObj", ("chars1","chars2","lineArray"))
Unfortunately Python is just one example. C#, C++/QT, and ObjectiveC all use arrays/lists/tuples as return values, and some of the ports not maintained in this repo (such as Go) also use arrays.
Activity
NeilFraser commentedon May 24, 2018
Good catch, the wiki is out of date. Use these three lines instead:
Fixing the wiki page now. Thanks!
urigoren commentedon May 25, 2018
Thank you for the swift response, if you're editing the docs - you might want to use more explicit variable name than
a.For example:
Also, why is
diff_linesToWordsa part of the docs and not a part of the library itself ?Thank you so much !
NeilFraser commentedon May 25, 2018
Your suggestion is optimal for JavaScript and Java where an object is returned, but in other languages such as Python the return value is an array. So I think the code on the wiki is a good compromise, that makes it relatively easy for people to translate the example into the language they are using.
The reason
diff_linesToWordsis not part of the library is that nobody can agree on the definition of a word. I developed the word count for Google Docs, and learned that it's a fairly arbitrary number. Open Office, MS Word, and Google Docs all report significantly different word counts for the same non-trivial document. For example, is "coca-cola.com" one or two or three words? And then there's the nightmare of what to do about CJK languages. If I were to add a word-splitting algorithm to diff-match-patch, I'd end up dealing with conflicting bug reports for the rest of my life. :)urigoren commentedon May 25, 2018
Got your note a regarding the word-splitting, didn't think about that.
However, regarding the return type of
diff_linesToChars_, I am not a master inluaordart, but inpython, its super simple.Just wrap the return value with a
namedtuple.This will allow your users to access the object as an array or by its attributes - backward compatible, and it works for
python2andpython3.See example:
And all you need to do is replace this line with
If you grant me collaborator rights, I can open a pull request myself
NeilFraser commentedon May 25, 2018
Unfortunately Python is just one example. C#, C++/QT, and ObjectiveC all use arrays/lists/tuples as return values, and some of the ports not maintained in this repo (such as Go) also use arrays.