String returns a string for the underlying value. If this value is not of type string, pongo2 tries to convert it. Currently the following types for underlying values are supported: 1. string 2. int/uint (any size) 3. float (any precision) 4. bool 5. time.Time 6. String() will be called on the unde
()
| 103 | // NIL values will lead to an empty string. Unsupported types are leading |
| 104 | // to their respective type name. |
| 105 | func (v *Value) String() string { |
| 106 | if v.IsNil() { |
| 107 | return "" |
| 108 | } |
| 109 | |
| 110 | if t, ok := v.Interface().(fmt.Stringer); ok { |
| 111 | return t.String() |
| 112 | } |
| 113 | |
| 114 | switch v.getResolvedValue().Kind() { |
| 115 | case reflect.String: |
| 116 | return v.getResolvedValue().String() |
| 117 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 118 | return strconv.FormatInt(v.getResolvedValue().Int(), 10) |
| 119 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: |
| 120 | return strconv.FormatUint(v.getResolvedValue().Uint(), 10) |
| 121 | case reflect.Float32, reflect.Float64: |
| 122 | return fmt.Sprintf("%f", v.getResolvedValue().Float()) |
| 123 | case reflect.Bool: |
| 124 | if v.Bool() { |
| 125 | return "True" |
| 126 | } |
| 127 | return "False" |
| 128 | } |
| 129 | |
| 130 | logf("Value.String() not implemented for type: %s\n", v.getResolvedValue().Kind().String()) |
| 131 | return v.getResolvedValue().String() |
| 132 | } |
| 133 | |
| 134 | // Integer returns the underlying value as an integer (converts the underlying |
| 135 | // value, if necessary). If it's not possible to convert the underlying value, |