forked from getantibody/antibody
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.go
38 lines (31 loc) · 708 Bytes
/
sort.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
package antibodylib
import (
"sort"
"strings"
)
type indexedLine struct {
idx int
line string
}
type indexedLines []indexedLine
// Len is needed by Sort interface
func (slice indexedLines) Len() int {
return len(slice)
}
// Less is needed by Sort interface
func (slice indexedLines) Less(i, j int) bool {
return slice[i].idx < slice[j].idx
}
// Swap is needed by Sort interface
func (slice indexedLines) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}
// Sort all lines and join them in a string
func (slice indexedLines) String() string {
sort.Sort(slice)
var lines []string
for _, line := range slice {
lines = append(lines, line.line)
}
return strings.Join(lines, "\n")
}