-
Notifications
You must be signed in to change notification settings - Fork 0
/
ident.go
33 lines (27 loc) · 905 Bytes
/
ident.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
package ident
import (
"strings"
"google.golang.org/protobuf/compiler/protogen"
)
// WithChild returns id with a dotted child on its name part.
// Example: Message -> Message.Field
func WithChild(id protogen.GoIdent, child string) protogen.GoIdent {
return WithSuffix(id, "."+child)
}
// WithPrefix returns id with a prefix on its name part.
// Example: Message -> PrefixedMessage
func WithPrefix(id protogen.GoIdent, prefix string) protogen.GoIdent {
id.GoName = prefix + id.GoName
return id
}
// WithSuffix returns id with a suffix on its name part.
// Example: Message becomes MessageSuffix
func WithSuffix(id protogen.GoIdent, suffix string) protogen.GoIdent {
id.GoName = id.GoName + suffix
return id
}
// LeafName returns the leaf name (after the last dot, if any) in id.
func LeafName(id protogen.GoIdent) string {
names := strings.Split(id.GoName, ".")
return names[len(names)-1]
}