mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-23 04:40:49 +01:00
Add switch to 'unquoteIfQuoted' to check for string as well as []byte types.
This commit is contained in:
parent
74d668a796
commit
9d980d3d4d
1 changed files with 17 additions and 9 deletions
24
decimal.go
24
decimal.go
|
@ -638,15 +638,23 @@ func round(n float64) int64 {
|
|||
}
|
||||
|
||||
func unquoteIfQuoted(value interface{}) (string, error) {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Could not convert value '%+v' to byte array",
|
||||
|
||||
switch v := value.(type) {
|
||||
|
||||
case string:
|
||||
str := strings.Replace(v, `"`, ``, -1)
|
||||
return str, nil
|
||||
|
||||
case []byte:
|
||||
if len(v) > 2 && v[0] == '"' && v[len(v)-1] == '"' {
|
||||
v = v[1 : len(v)-1]
|
||||
}
|
||||
return string(v), nil
|
||||
|
||||
default:
|
||||
return "", fmt.Errorf("Could not convert value '%+v' to any type",
|
||||
value)
|
||||
|
||||
}
|
||||
|
||||
// If the amount is quoted, strip the quotes
|
||||
if len(bytes) > 2 && bytes[0] == '"' && bytes[len(bytes)-1] == '"' {
|
||||
bytes = bytes[1 : len(bytes)-1]
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue