valueTokenFromInterface takes any valid value and returns a value token to represent it
(v interface{})
| 114 | // valueTokenFromInterface takes any valid value and |
| 115 | // returns a value token to represent it |
| 116 | func 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 |