MCPcopy Create free account
hub / github.com/araddon/qlbridge / ValueToStrings

Function ValueToStrings

value/coerce.go:197–223  ·  view source on GitHub ↗

ValueToStrings convert all scalar values to their go []string.

(val Value)

Source from the content-addressed store, hash-verified

195
196// ValueToStrings convert all scalar values to their go []string.
197func ValueToStrings(val Value) ([]string, bool) {
198 if val == nil || val.Err() {
199 return nil, false
200 }
201 switch v := val.(type) {
202 case StringValue:
203 return []string{v.Val()}, true
204 case TimeValue:
205 return []string{fmt.Sprintf("%v", v.Val())}, true
206 case ByteSliceValue:
207 return []string{string(v.Val())}, true
208 case NumericValue, BoolValue, IntValue:
209 return []string{val.ToString()}, true
210 case Slice:
211 if v.Len() == 0 {
212 return nil, false
213 }
214 vals := make([]string, v.Len())
215 for i, val := range v.SliceValue() {
216 if val != nil {
217 vals[i] = val.ToString()
218 }
219 }
220 return vals, true
221 }
222 return nil, false
223}
224
225// is this boolean string?
226func IsBool(sv string) bool {

Callers 1

TestValueToStringsFunction · 0.85

Calls 5

ErrMethod · 0.65
ToStringMethod · 0.65
LenMethod · 0.65
SliceValueMethod · 0.65
ValMethod · 0.45

Tested by 1

TestValueToStringsFunction · 0.68