Line Diff causes an exception
See original GitHub issueRunning the example usage from here on the javascript version:
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 (<anonymous>:2:190) at <anonymous>:6:19
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to know the exact line of code where an exception has ...
If I generate an exception on my own, I can include any info into the exception: a number of code line and name...
Read more >C. diff: Symptoms, Causes, Transmission, Treatment & More
C. diff is a type of bacterium that sometimes causes gastrointestinal symptoms, such as diarrhea and stomach cramps. Discover how this bacterium is...
Read more >Exceptions and Error Handling, C++ FAQ
“But throwing an exception from a constructor invoked by new causes a memory leak!” Nonsense! ... Give it 4,000 lines and you'll see...
Read more >Best Practices for exceptions - .NET
Learn best practices for exceptions, such as using try/catch/finally, handling common conditions without exceptions, and using predefined .
Read more >Types of Exceptions in Java
This type of exception occurs when you try to access an array with an invalid index value. The value you are providing is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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. 😃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_linesToWords
a part of the docs and not a part of the library itself ?Thank you so much !