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

Method DiffCharsToLines

diffmatchpatch/diff.go:408–422  ·  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

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

Calls 1

runeToIntFunction · 0.85