question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line Diff causes an exception

See original GitHub issue

Running 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
NeilFrasercommented, 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_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. 😃

1reaction
urigorencommented, 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:

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 ?

Thank you so much !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found