-
Notifications
You must be signed in to change notification settings - Fork 47
/
text.go
53 lines (43 loc) · 1.13 KB
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Copyright (c) 2021 - Present. Blend Labs, Inc. All rights reserved
Use of this source code is governed by a MIT license that can be found in the LICENSE file.
*/
package diff
import "bytes"
// Text converts a []Diff into a text report.
func Text(diffs []Diff) string {
var buff bytes.Buffer
for _, diff := range diffs {
text := diff.Text
switch diff.Type {
case DiffInsert:
_, _ = buff.WriteString("+")
_, _ = buff.WriteString(text)
case DiffDelete:
_, _ = buff.WriteString("-")
_, _ = buff.WriteString(text)
}
}
return buff.String()
}
// Text1 computes and returns the source text (all equalities and deletions).
func Text1(diffs []Diff) string {
//StringBuilder text = new StringBuilder()
var text bytes.Buffer
for _, aDiff := range diffs {
if aDiff.Type != DiffInsert {
_, _ = text.WriteString(aDiff.Text)
}
}
return text.String()
}
// Text2 computes and returns the destination text (all equalities and insertions).
func Text2(diffs []Diff) string {
var text bytes.Buffer
for _, aDiff := range diffs {
if aDiff.Type != DiffDelete {
_, _ = text.WriteString(aDiff.Text)
}
}
return text.String()
}