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

Function ValueToString

value/coerce.go:161–194  ·  view source on GitHub ↗

ValueToString convert all scalar values to their go string.

(val Value)

Source from the content-addressed store, hash-verified

159
160// ValueToString convert all scalar values to their go string.
161func ValueToString(val Value) (string, bool) {
162 if val == nil || val.Err() {
163 return "", false
164 }
165 switch v := val.(type) {
166 case StringValue:
167 return v.Val(), true
168 case TimeValue:
169 return fmt.Sprintf("%v", v.Val()), true
170 case ByteSliceValue:
171 return string(v.Val()), true
172 case NumericValue, BoolValue, IntValue:
173 return val.ToString(), true
174 case Slice:
175 // This is controversial, if we are demanding a "ToString"
176 // should we:
177 // 1) take first?
178 // 2) append comma separated?
179 // 3) error?
180 //
181 // Our answer is that we are demanding a scalar string
182 // and going to take first. calling function would have had to do type detection
183 // if they wanted something else.
184 if v.Len() == 0 {
185 return "", false
186 }
187 v1 := v.SliceValue()[0]
188 if v1 == nil {
189 return "", false
190 }
191 return v1.ToString(), true
192 }
193 return "", false
194}
195
196// ValueToStrings convert all scalar values to their go []string.
197func ValueToStrings(val Value) ([]string, bool) {

Callers 15

containsEvalFunction · 0.92
lowerCaseEvalFunction · 0.92
upperCaseEvalFunction · 0.92
titleCaseEvalFunction · 0.92
splitEvalFunction · 0.92
joinEvalFunction · 0.92
emailNameEvalFunction · 0.92
emailDomainEvalFunction · 0.92
qsEvalFunction · 0.92
qsDeprecateEvalFunction · 0.92
urlMinusQsEvalFunction · 0.92
ValidateMethod · 0.92

Calls 5

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

Tested by 1

TestValueToStringFunction · 0.68