java-diff-utils / java-diff-utils

Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.

Home Page:https://java-diff-utils.github.io/java-diff-utils/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request - To Merge Differences

gvjoshi25 opened this issue · comments

Describe the Feature
A new request to consider including whitespace (space in my case) to represent the differences.

To Reproduce
Steps to reproduce the behavior:

  1. Example data --> Included in snippet.
  2. simple program snippet
import java.util.Arrays;
import java.util.List;

import com.github.difflib.text.DiffRow;
import com.github.difflib.text.DiffRowGenerator;

public class ShowDiffViewUsingJavaDiffUtils {

    static String leftString = "A sample string to test this tool.";
    static String rightString = "A sample string is defined here and will be used to test diff library.";

    public static void main(String[] args) throws Throwable {

      //create a configured DiffRowGenerator
        DiffRowGenerator generator = DiffRowGenerator.create()
                        .ignoreWhiteSpaces(true)
                        .showInlineDiffs(true)
                        .mergeOriginalRevised(false)
                        .inlineDiffByWord(true)
                        .oldTag(f -> "--")
                        .newTag(f -> "++")
                        .build();

        //compute the differences for two test texts.
        List<DiffRow> rows = generator.generateDiffRows(
                        Arrays.asList(leftString),
                        Arrays.asList(rightString));
        
        rows.stream().forEach(r -> {
            System.out.println("OldLine: " + r.getOldLine());
            System.out.println("NewLine: " + r.getNewLine());
        });

    }

}

  1. See error - NA.

Expected behavior
The output of my program is:

OldLine: A sample string to test --this-- --tool--.
NewLine: A sample string ++is defined here and will be used ++to test ++diff++ ++library++.

I would like to have this diff tool to consider whitespace. e.g. consider whitespace between this tool for the differences.
Expected output:

OldLine: A sample string to test --this tool--.
NewLine: A sample string ++is defined here and will be used ++to test ++diff library++.

I have tried all possible configurations to achieve this, but no luck, hence raising this request. If the feature does exist, please share the details.

System

  • Java version - 1.8
  • Version - 4.12

Stale issue message