-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
62 lines (53 loc) · 932 Bytes
/
util.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
54
55
56
57
58
59
60
61
62
package php81
import (
"os"
"strings"
"github.com/emicklei/proto"
)
func loadProto(filename string) (*proto.Proto, error) {
reader, err := os.Open(filename)
if err != nil {
return nil, err
}
defer reader.Close()
parser := proto.NewParser(reader)
return parser.Parse()
}
func comment(comment *proto.Comment) string {
if comment == nil {
return ""
}
result := ""
for _, line := range comment.Lines {
line = strings.TrimSpace(line)
if line == "" {
break
}
result += " " + line
}
if len(result) > 1 {
return result[1:]
}
return ""
}
func description(comment *proto.Comment) string {
if comment == nil {
return ""
}
grab := false
result := []string{}
for _, line := range comment.Lines {
line = strings.TrimSpace(line)
if line == "" {
if grab {
break
}
grab = true
continue
}
if grab {
result = append(result, line)
}
}
return strings.Join(result, "\n")
}