MCPcopy
hub / github.com/tomnomnom/gron / valueTokenFromInterface

Function valueTokenFromInterface

token.go:116–137  ·  view source on GitHub ↗

valueTokenFromInterface takes any valid value and returns a value token to represent it

(v interface{})

Source from the content-addressed store, hash-verified

114// valueTokenFromInterface takes any valid value and
115// returns a value token to represent it
116func valueTokenFromInterface(v interface{}) token {
117 switch vv := v.(type) {
118
119 case map[string]interface{}:
120 return token{"{}", typEmptyObject}
121 case []interface{}:
122 return token{"[]", typEmptyArray}
123 case json.Number:
124 return token{vv.String(), typNumber}
125 case string:
126 return token{quoteString(vv), typString}
127 case bool:
128 if vv {
129 return token{"true", typTrue}
130 }
131 return token{"false", typFalse}
132 case nil:
133 return token{"null", typNull}
134 default:
135 return token{"", typError}
136 }
137}
138
139// quoteString takes a string and returns a quoted and
140// escaped string valid for use in gron output

Callers 3

fillMethod · 0.85

Calls 2

quoteStringFunction · 0.85
StringMethod · 0.80

Tested by 2