Move trim quotes logic to separate function

This commit is contained in:
Narayanan Singaram
2019-03-04 13:19:18 -08:00
parent ea3d5e68db
commit ed2ad860c6

View File

@@ -152,11 +152,7 @@ func (o *addMetadataOptions) convertToMap(arg string) (map[string]string, error)
}
// remove quotes if value is quoted
if len(result[kv[0]]) > 0 &&
result[kv[0]][:1] == "\"" &&
result[kv[0]][len(result[kv[0]])-1:] == "\"" {
result[kv[0]] = result[kv[0]][1 : len(result[kv[0]])-1]
}
result[kv[0]] = trimQuotes(result[kv[0]])
}
return result, nil
}
@@ -188,3 +184,12 @@ func (o *addMetadataOptions) writeToMap(m map[string]string, kind kindOfAdd) err
func (o *addMetadataOptions) makeError(input string, message string) error {
return fmt.Errorf("invalid %s: %s (%s)", o.kind, input, message)
}
func trimQuotes(s string) string {
if len(s) >= 2 {
if s[0] == '"' && s[len(s)-1] == '"' {
return s[1 : len(s)-1]
}
}
return s
}