MCPcopy
hub / github.com/TomWright/dasel / string

Method string

model/value.go:64–120  ·  view source on GitHub ↗
(indent int)

Source from the content-addressed store, hash-verified

62}
63
64func (v *Value) string(indent int) string {
65 switch v.Type() {
66 case TypeString:
67 val, err := v.StringValue()
68 if err != nil {
69 panic(err)
70 }
71 return fmt.Sprintf("string{%s}", val)
72 case TypeInt:
73 val, err := v.IntValue()
74 if err != nil {
75 panic(err)
76 }
77 return fmt.Sprintf("int{%d}", val)
78 case TypeFloat:
79 val, err := v.FloatValue()
80 if err != nil {
81 panic(err)
82 }
83 return fmt.Sprintf("float(%g)", val)
84 case TypeBool:
85 val, err := v.BoolValue()
86 if err != nil {
87 panic(err)
88 }
89 return fmt.Sprintf("bool{%t}", val)
90 case TypeMap:
91 res := "{\n"
92 if err := v.RangeMap(func(k string, v *Value) error {
93 res += fmt.Sprintf("%s%s: %s,\n", indentStr(indent+1), k, v.string(indent+1))
94 return nil
95 }); err != nil {
96 panic(err)
97 }
98 return res + indentStr(indent) + "}"
99 case TypeSlice:
100 md := ""
101 if v.IsSpread() {
102 md = "spread, "
103 }
104 if v.IsBranch() {
105 md += "branch, "
106 }
107 res := fmt.Sprintf("array[%s]{\n", strings.TrimSuffix(md, ", "))
108 if err := v.RangeSlice(func(k int, v *Value) error {
109 res += fmt.Sprintf("%s%d: %s,\n", indentStr(indent+1), k, v.string(indent+1))
110 return nil
111 }); err != nil {
112 panic(err)
113 }
114 return res + indentStr(indent) + "}"
115 case TypeNull:
116 return indentStr(indent) + "null"
117 default:
118 return fmt.Sprintf("unknown[%s]", v.Interface())
119 }
120}
121

Callers 1

StringMethod · 0.95

Calls 11

TypeMethod · 0.95
StringValueMethod · 0.95
IntValueMethod · 0.95
FloatValueMethod · 0.95
BoolValueMethod · 0.95
RangeMapMethod · 0.95
IsSpreadMethod · 0.95
IsBranchMethod · 0.95
RangeSliceMethod · 0.95
InterfaceMethod · 0.95
indentStrFunction · 0.85

Tested by

no test coverage detected