Skip to content

Commit

Permalink
diff: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Dec 24, 2024
1 parent 59dc3ff commit 382df7c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 62 deletions.
40 changes: 0 additions & 40 deletions modules/diferenco/diferenco.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"slices"
"strings"
)

Expand Down Expand Up @@ -96,52 +95,13 @@ func commonSuffixLength[E comparable](a, b []E) int {
return i
}

func slicesHasSuffix[E comparable](a, suffix []E) bool {
return len(a) >= len(suffix) && slices.Equal(a[len(a)-len(suffix):], suffix)
}

func slicesHasPrefix[E comparable](a, prefix []E) bool {
return len(a) >= len(prefix) && slices.Equal(a[:len(prefix)], prefix)
}

// slicesIndex is the equivalent of strings.Index for rune slices.
func slicesIndex[E comparable](s1, s2 []E) int {
last := len(s1) - len(s2)
for i := 0; i <= last; i++ {
if slices.Equal(s1[i:i+len(s2)], s2) {
return i
}
}
return -1
}

// slicesIndexOf returns the index of pattern in target, starting at target[i].
func slicesIndexOf[E comparable](target, pattern []E, i int) int {
if i > len(target)-1 {
return -1
}
if i <= 0 {
return slicesIndex(target, pattern)
}
ind := slicesIndex(target[i:], pattern)
if ind == -1 {
return -1
}
return ind + i
}

type Change struct {
P1 int // before: position in before
P2 int // after: position in after
Del int // number of elements that deleted from a
Ins int // number of elements that inserted into b
}

type Dfio[E comparable] struct {
T Operation
E []E
}

// StringDiff represents one diff operation
type StringDiff struct {
Type Operation
Expand Down
22 changes: 0 additions & 22 deletions modules/diferenco/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,6 @@ func (s *Sink) WriteLine(w io.Writer, E ...int) {
}
}

func (s *Sink) AsStringDiff(o []Dfio[int]) []StringDiff {
var newLine string
switch s.NewLine {
case NEWLINE_CRLF:
newLine = "\r\n"
case NEWLINE_LF:
newLine = "\n"
}
diffs := make([]StringDiff, 0, len(o))
for _, e := range o {
ss := make([]string, 0, len(e.E))
for _, i := range e.E {
ss = append(ss, s.Lines[i])
}
diffs = append(diffs, StringDiff{
Type: e.T,
Text: strings.Join(ss, newLine),
})
}
return diffs
}

func (s *Sink) addEqualLines(h *Hunk, index []int, start, end int) int {
delta := 0
for i := start; i < end; i++ {
Expand Down

0 comments on commit 382df7c

Please sign in to comment.