Code Monkey home page Code Monkey logo

Comments (6)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 25, 2024
This is why DMP doesn't have a built-in word mode; no two people can agree on 
what a word is, what to do with punctuation, etc.  By writing your own function 
as the linked page describes, you get to define your own delimiters.

To implement your desired behaviour, you might want something like this in your 
diff_linesToWords function:

if (text.charAt(0).match(/\s/) {
  // The next token will be whitespace.
  lineEnd = text.indexOf(/\S/, lineStart);
} else {
  // The next token will be a word.
  lineEnd = text.indexOf(/\s/, lineStart);
}

Original comment by [email protected] on 19 May 2011 at 5:54

  • Changed state: Done
  • Added labels: ****
  • Removed labels: ****

from google-diff-match-patch.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 25, 2024
Oops, I forgot that text isn't being chopped at each iteration.  That first 
line should be:

if (text.charAt(lineStart).match(/\s/) {

Original comment by [email protected] on 19 May 2011 at 5:57

  • Added labels: ****
  • Removed labels: ****

from google-diff-match-patch.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 25, 2024
Currently working on something else but I will get back to my issue and try 
this out sometime soon. Thanks a lot for the help, very much appreciated!

Original comment by [email protected] on 23 May 2011 at 9:11

  • Added labels: ****
  • Removed labels: ****

from google-diff-match-patch.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 25, 2024
I'm trying to use this but am not getting desired results...

1. First off, I don't think indexOf() takes regex, not according to 
specification anyway apparently. I am using a custom "regexIndexOf()" function 
i found online, here it is:
===CODE===
String.prototype.regexIndexOf = function(regex, startpos) {
 var indexOf = this.substring(startpos || 0).search(regex);
 return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf;
}
===/CODE===


2. It doesn't seem to work, I still see whitespace (in my case ' ' space 
character) considered part of its adjacent previous word. To illustrate, 
consider this string "Hello world people"
I need DMP to diff it by words as follows:
[Hello] [ ] [world] [ ] [people]
Instead, I get:
[Hello ] [world ] [people]

Thanks in advance for your time if you get around to this... :)

Original comment by [email protected] on 2 Jun 2011 at 10:04

  • Added labels: ****
  • Removed labels: ****

from google-diff-match-patch.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 25, 2024
*
(when I said "it doesn't seem to work" I am referring to your snippet you 
posted above, including your follow-up correction)

Original comment by [email protected] on 2 Jun 2011 at 10:05

  • Added labels: ****
  • Removed labels: ****

from google-diff-match-patch.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 25, 2024
Hm... Why not just Add string/array with word delimiters and enum such like:

Enum TreatWord
{
DelimeterOnStart
DelimeterOnEnd
DelimeterOnBothSides
}

And depending on this make diff for words. This will cover all situations "on 
what a word is".

By the way, the linked example is obsolete and for adding word diff 
functionality you have to change two methods as I can remember.

Original comment by [email protected] on 25 Jun 2011 at 11:46

  • Added labels: ****
  • Removed labels: ****

from google-diff-match-patch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.