MCPcopy Create free account
hub / github.com/sergi/go-diff / diffMainRunes

Method diffMainRunes

diffmatchpatch/diff.go:100–132  ·  view source on GitHub ↗
(text1, text2 []rune, checklines bool, deadline time.Time)

Source from the content-addressed store, hash-verified

98}
99
100func (dmp *DiffMatchPatch) diffMainRunes(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {
101 if runesEqual(text1, text2) {
102 var diffs []Diff
103 if len(text1) > 0 {
104 diffs = append(diffs, Diff{DiffEqual, string(text1)})
105 }
106 return diffs
107 }
108 // Trim off common prefix (speedup).
109 commonlength := commonPrefixLength(text1, text2)
110 commonprefix := text1[:commonlength]
111 text1 = text1[commonlength:]
112 text2 = text2[commonlength:]
113
114 // Trim off common suffix (speedup).
115 commonlength = commonSuffixLength(text1, text2)
116 commonsuffix := text1[len(text1)-commonlength:]
117 text1 = text1[:len(text1)-commonlength]
118 text2 = text2[:len(text2)-commonlength]
119
120 // Compute the diff on the middle block.
121 diffs := dmp.diffCompute(text1, text2, checklines, deadline)
122
123 // Restore the prefix and suffix.
124 if len(commonprefix) != 0 {
125 diffs = append([]Diff{{DiffEqual, string(commonprefix)}}, diffs...)
126 }
127 if len(commonsuffix) != 0 {
128 diffs = append(diffs, Diff{DiffEqual, string(commonsuffix)})
129 }
130
131 return dmp.DiffCleanupMerge(diffs)
132}
133
134// diffCompute finds the differences between two rune slices. Assumes that the texts do not have any common prefix or suffix.
135func (dmp *DiffMatchPatch) diffCompute(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {

Callers 4

DiffMainRunesMethod · 0.95
diffComputeMethod · 0.95
diffLineModeMethod · 0.95
diffBisectSplitMethod · 0.95

Calls 5

diffComputeMethod · 0.95
DiffCleanupMergeMethod · 0.95
runesEqualFunction · 0.85
commonPrefixLengthFunction · 0.85
commonSuffixLengthFunction · 0.85

Tested by

no test coverage detected