Skip to content

Feature Request - To Merge Differences #168

Description

@gvjoshi25

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions