Skip to content

Commit

Permalink
updated dep
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Oct 30, 2024
1 parent 74b3f1f commit 96ed57b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions internal/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ func (r Repeated) Convert(toType reflect.Type) (interface{}, error) {
case reflect.Float64:
v, err := r.AsFloats64()
return v, err
case reflect.Bool:
v, err := r.AsBools()
return v, err
case reflect.Float32:
v, err := r.AsFloats32()
return v, err
Expand Down
18 changes: 15 additions & 3 deletions internal/converter/repeated.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func (r Repeated) AsFloats64() ([]float64, error) {
return result, nil
}

func (r Repeated) AsBools() ([]bool, error) {
var result = make([]bool, 0, len(r))
for _, item := range r {
v, err := strconv.ParseBool(item)
if err != nil {
return nil, fmt.Errorf("failed to convert %v into %T, %w", r, result, err)
}
result = append(result, v)
}
return result, nil
}

func (r Repeated) AsFloats32() ([]float32, error) {
var result = make([]float32, 0, len(r))
for _, item := range r {
Expand All @@ -69,20 +81,20 @@ func (r Repeated) AsFloats32() ([]float32, error) {
return result, nil
}

func NewRepeated(text string, isNumeric bool) Repeated {
func NewRepeated(text string, trimSpace bool) Repeated {
if text == "" {
return Repeated{}
}
if text[0] == '[' && text[len(text)-1] == ']' { //remove enclosure if needed
text = text[1 : len(text)-1]
}
elements := strings.Split(text, ",")
if !isNumeric {
if !trimSpace {
return elements
}
var result = make(Repeated, 0, len(elements))
for _, elem := range elements {
if isNumeric {
if trimSpace {
if elem = strings.TrimSpace(elem); elem == "" {
continue
}
Expand Down

0 comments on commit 96ed57b

Please sign in to comment.