MCPcopy
hub / github.com/flosch/pongo2 / String

Method String

value.go:105–132  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

103// NIL values will lead to an empty string. Unsupported types are leading
104// to their respective type name.
105func (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,

Callers 15

LessMethod · 0.95
IntegerMethod · 0.45
FloatMethod · 0.45
BoolMethod · 0.45
IsTrueMethod · 0.45
NegateMethod · 0.45
LenMethod · 0.45
SliceMethod · 0.45
IndexMethod · 0.45
ContainsMethod · 0.45
IterateOrderMethod · 0.45
LessMethod · 0.45

Calls 6

IsNilMethod · 0.95
InterfaceMethod · 0.95
getResolvedValueMethod · 0.95
BoolMethod · 0.95
logfFunction · 0.85
FloatMethod · 0.80

Tested by 1

TestMiscMethod · 0.36