Skip to content

Commit

Permalink
fix quote
Browse files Browse the repository at this point in the history
  • Loading branch information
ixiongjianbo committed Jun 27, 2023
1 parent e5be5c3 commit 860ef23
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func copyFields(src interface{}, dst interface{}) {
}
}

// Quote Example
// Quote([]string{"aa", "bbb"}) result:['aa' 'bbb']
func Quote[T []string | []int | []int32 | []int64 | float64 | float32](from T, sign ...string) (to []string) {
var s = `'`
if len(sign) > 0 {
Expand All @@ -86,11 +88,13 @@ func Quote[T []string | []int | []int32 | []int64 | float64 | float32](from T, s
valueOf = valueOf.Elem()
}
for curRow := 0; curRow < valueOf.Len(); curRow++ {
to = append(to, fmt.Sprintf(`%s%v%s`, s, valueOf.Field(curRow).Interface(), s))
to = append(to, fmt.Sprintf(`%s%v%s`, s, valueOf.Index(curRow).Interface(), s))
}
return to
}

// QuoteString Example
// QuoteString([]string{"aa", "bbb"}) result:'aa','bbb'
func QuoteString[T []string | []int | []int32 | []int64 | float64 | float32](from T, sign ...string) (to string) {
var s = `'`
if len(sign) > 0 {
Expand All @@ -102,7 +106,7 @@ func QuoteString[T []string | []int | []int32 | []int64 | float64 | float32](fro
}
var toSlice []string
for curRow := 0; curRow < valueOf.Len(); curRow++ {
toSlice = append(toSlice, fmt.Sprintf(`%s%v%s`, s, valueOf.Field(curRow).Interface(), s))
toSlice = append(toSlice, fmt.Sprintf(`%s%v%s`, s, valueOf.Index(curRow).Interface(), s))
}
return strings.Join(toSlice, `,`)
}
Expand Down

0 comments on commit 860ef23

Please sign in to comment.