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

Function diffText1Prefix

diffmatchpatch/patch.go:557–578  ·  view source on GitHub ↗

diffText1Prefix returns the first n bytes of DiffText1(diffs) without building the whole text. If byte n falls inside a multi-byte rune, the prefix stops before that rune.

(diffs []Diff, n int)

Source from the content-addressed store, hash-verified

555// diffText1Prefix returns the first n bytes of DiffText1(diffs) without building the whole text.
556// If byte n falls inside a multi-byte rune, the prefix stops before that rune.
557func diffText1Prefix(diffs []Diff, n int) string {
558 var text strings.Builder
559 for _, aDiff := range diffs {
560 if aDiff.Type == DiffInsert {
561 continue
562 }
563 remaining := n - text.Len()
564 if remaining <= 0 {
565 break
566 }
567 if len(aDiff.Text) >= remaining {
568 cut := alignRuneStart(aDiff.Text, remaining)
569 if text.Len() == 0 {
570 return aDiff.Text[:cut]
571 }
572 _, _ = text.WriteString(aDiff.Text[:cut])
573 break
574 }
575 _, _ = text.WriteString(aDiff.Text)
576 }
577 return text.String()
578}
579
580// PatchToText takes a list of patches and returns a textual representation.
581func (dmp *DiffMatchPatch) PatchToText(patches []Patch) string {

Callers 2

PatchSplitMaxMethod · 0.85

Calls 2

alignRuneStartFunction · 0.85
StringMethod · 0.45

Tested by 1