1package opts 2 3// QuotedString is a string that may have extra quotes around the value. The 4// quotes are stripped from the value. 5type QuotedString struct { 6 value *string 7} 8 9// Set sets a new value 10func (s *QuotedString) Set(val string) error { 11 *s.value = trimQuotes(val) 12 return nil 13} 14 15// Type returns the type of the value 16func (s *QuotedString) Type() string { 17 return "string" 18} 19 20func (s *QuotedString) String() string { 21 return *s.value 22} 23 24func trimQuotes(value string) string { 25 lastIndex := len(value) - 1 26 for _, char := range []byte{'\'', '"'} { 27 if value[0] == char && value[lastIndex] == char { 28 return value[1:lastIndex] 29 } 30 } 31 return value 32} 33 34// NewQuotedString returns a new quoted string option 35func NewQuotedString(value *string) *QuotedString { 36 return &QuotedString{value: value} 37} 38