Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Free Diff library wanted

Thread view: 
Zsolt Koppany - 27 Jun 2006 12:17 GMT
Hi,

can somebody help me to find a free Diff library? I would like to compare
texts and figure out the different lines but also differences in the lines.

Zsolt
Christopher Benson-Manica - 27 Jun 2006 14:20 GMT
> can somebody help me to find a free Diff library? I would like to compare
> texts and figure out the different lines but also differences in the lines.

1) GIYF
2) For what programmatic purpose?  Various command-line utilities
exist that can do this sort of thing for you; perhaps you could use
them for your purpose.

Signature

Christopher Benson-Manica  | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org    | don't, I need to know.  Flames welcome.

Rogan Dawes - 27 Jun 2006 14:38 GMT
> Hi,
>
> can somebody help me to find a free Diff library? I would like to compare
> texts and figure out the different lines but also differences in the lines.
>
> Zsolt

I have written a Diff implementation, along with a viewer that displays
the differences either inline (with colour highlighting) or side by side
(also with highlighting).

You can get the bits from my WebScarab repository at:

Diff class:

<http://dawes.za.net/gitweb.cgi?p=dawes.za.net/rogan/webscarab/webscarab.git;a=bl
ob;h=52f44b0f1912a67810498778fe3aa4b52ae8de64;hb=373301b0048c43dfacd1c7965f13bf8
cccd7d317;f=src/org/owasp/webscarab/util/Diff.java
>

DiffPanel class:

<http://dawes.za.net/gitweb.cgi?p=dawes.za.net/rogan/webscarab/webscarab.git;a=bl
ob;h=539ef5537f9f00d70c4df7c801c0a24704038776;hb=373301b0048c43dfacd1c7965f13bf8
cccd7d317;f=src/org/owasp/webscarab/util/swing/DiffPanel.java
>

NoWrapEditorKit class: (used by DiffPanel.class)

<http://dawes.za.net/gitweb.cgi?p=dawes.za.net/rogan/webscarab/webscarab.git;a=bl
ob;h=1977dd8611e3333437f5436afe5be545d6749488;hb=373301b0048c43dfacd1c7965f13bf8
cccd7d317;f=src/org/owasp/webscarab/util/swing/NoWrapEditorKit.java
>

These classes are part of a larger program, so you will need to edit
package names, etc to suit.

There are a couple of examples showing how to use it in the DiffPanel
main method.

The diff algorithm is O(m*n) where m and n are the length of the 2
source documents. Obviously, the longer the documents, the longer it is
going to take. One approach to reduce n and m by tokenising the source
documents, typically along line or word boundaries.

So, what you can do is the following:

// get the edits by line
List edits = Diff.getEdits(src, dst, '\n');
// refine the edits to get the minimum edits
edits = Diff.refine(src, dst, edits);
// show the differences visually
panel.showDifferences(src, dst, edits);

Code is licensed under the GPL.

Let me know if you have any questions. Or any improvements . . . ;-)

Rogan


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.