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

Method DiffCharsToLines

diffmatchpatch/diff.go:404–418  ·  view source on GitHub ↗

DiffCharsToLines rehydrates the text in a diff from a string of line hashes to real lines of text.

(diffs []Diff, lineArray []string)

Source from the content-addressed store, hash-verified

402
403// DiffCharsToLines rehydrates the text in a diff from a string of line hashes to real lines of text.
404func (dmp *DiffMatchPatch) DiffCharsToLines(diffs []Diff, lineArray []string) []Diff {
405 hydrated := make([]Diff, 0, len(diffs))
406 for _, aDiff := range diffs {
407 runes := []rune(aDiff.Text)
408 text := make([]string, len(runes))
409
410 for i, r := range runes {
411 text[i] = lineArray[runeToInt(r)]
412 }
413
414 aDiff.Text = strings.Join(text, "")
415 hydrated = append(hydrated, aDiff)
416 }
417 return hydrated
418}
419
420// DiffCommonPrefix determines the common prefix length of two strings.
421func (dmp *DiffMatchPatch) DiffCommonPrefix(text1, text2 string) int {

Callers 6

diffLineModeMethod · 0.95
TestDiffCharsToLinesFunction · 0.80
TestDiffPartialLineIndexFunction · 0.80

Calls 1

runeToIntFunction · 0.85