Comments (6)
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
from google-diff-match-patch.
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
from google-diff-match-patch.
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
from google-diff-match-patch.
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
from google-diff-match-patch.
*
(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
from google-diff-match-patch.
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
from google-diff-match-patch.
Related Issues (20)
- Consider SQLCLR compatibility / eliminate dependency on System.Web for UrlEncode and UrlDecode HOT 3
- xIndex for instertion after location
- Demo pages not working HOT 4
- Levenshtein distance problem
- objc version generates wrong diffs
- When is this project transferred to github? HOT 1
- Javascript version doesn't handle astral code points correctly
- Diffs of text containing tab characters? to br
- moving to GitHub?
- Issue with match
- JS library gives wrong result.
- C# uses \n instead of \n\r or Environment.NewLine
- c# patch_toText + patch_fromText doesn't work
- Ruby port
- performance slow?
- NewLines appear broken in patches (Python 3, Django 1.6.1) HOT 2
- Patch for /trunk/python3/diff_match_patch.py
- Patch for /trunk/python3/diff_match_patch.py
- Uninitialized string offset: 0 (function diff_cleanupSemanticLossless)
- Text containing HTML HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-diff-match-patch.