Skip to content

Type for Diff.Text #93

@7AC

Description

@7AC

The current type for Text is string:

type Diff struct {
    Type Operation
    Text string
}

When I call DiffMainRunes() though looks like the Text in each diff needs to be interpreted as a []rune. Is there a reason not to define that as []rune (or use multiple types if it's used differently in other APIs)? It was hard to interpret since Text is not printable in this case, and the documentation doesn't mention this.

Here's my code:

    a := "foo\nbar\nbaz"
    b := "foo\nbaz\nfooz\nbarrington"
    dmp := diffmatchpatch.New()
    r1, r2, f := dmp.DiffLinesToRunes(a, b)
    fmt.Println(f)
    fmt.Println(r1)
    fmt.Println(r2)
    s := dmp.DiffMainRunes(r1, r2, false)
    for _, d := range s {
        fmt.Println("d.Type:", d.Type)
        // Printing d.Text here without converting it produces an empty string
        fmt.Println("d.Text:", []rune(d.Text))
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions