...
1 package aipreflect
2
3 import (
4 "fmt"
5 "unicode"
6 "unicode/utf8"
7 )
8
9
10
11 type GrammaticalName string
12
13
14 func (g GrammaticalName) Validate() error {
15 if len(g) == 0 {
16 return fmt.Errorf("validate grammatical name: must be non-empty")
17 }
18 for _, r := range g {
19 if !unicode.In(r, unicode.Letter, unicode.Digit) {
20 return fmt.Errorf("validate grammatical name '%s': contains forbidden character '%s'", g, string(r))
21 }
22 }
23 if r, _ := utf8.DecodeRuneInString(string(g)); !unicode.IsLower(r) {
24 return fmt.Errorf("validate grammatical name '%s': must be lowerCamelCase", g)
25 }
26 return nil
27 }
28
29
30 func (g GrammaticalName) UpperCamelCase() string {
31 return initialUpperCase(string(g))
32 }
33
View as plain text