...
1 package opts
2
3
4
5 type QuotedString struct {
6 value *string
7 }
8
9
10 func (s *QuotedString) Set(val string) error {
11 *s.value = trimQuotes(val)
12 return nil
13 }
14
15
16 func (s *QuotedString) Type() string {
17 return "string"
18 }
19
20 func (s *QuotedString) String() string {
21 return *s.value
22 }
23
24 func trimQuotes(value string) string {
25 if len(value) < 2 {
26 return value
27 }
28 lastIndex := len(value) - 1
29 for _, char := range []byte{'\'', '"'} {
30 if value[0] == char && value[lastIndex] == char {
31 return value[1:lastIndex]
32 }
33 }
34 return value
35 }
36
37
38 func NewQuotedString(value *string) *QuotedString {
39 return &QuotedString{value: value}
40 }
41
View as plain text