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)
| 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. |
| 557 | func 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. |
| 581 | func (dmp *DiffMatchPatch) PatchToText(patches []Patch) string { |