4f0d95fa |
package opts // import "github.com/docker/docker/opts" |
e4c1f077 |
// QuotedString is a string that may have extra quotes around the value. The
// quotes are stripped from the value. |
abe32de6 |
type QuotedString struct {
value *string
} |
e4c1f077 |
// Set sets a new value
func (s *QuotedString) Set(val string) error { |
abe32de6 |
*s.value = trimQuotes(val) |
e4c1f077 |
return nil
}
// Type returns the type of the value
func (s *QuotedString) Type() string {
return "string"
}
func (s *QuotedString) String() string { |
2f5f0af3 |
return *s.value |
e4c1f077 |
}
func trimQuotes(value string) string {
lastIndex := len(value) - 1
for _, char := range []byte{'\'', '"'} {
if value[0] == char && value[lastIndex] == char {
return value[1:lastIndex]
}
}
return value
} |
abe32de6 |
// NewQuotedString returns a new quoted string option
func NewQuotedString(value *string) *QuotedString {
return &QuotedString{value: value}
} |