MCPcopy
hub / github.com/pocketbase/pocketbase / ToUniqueStringSlice

Function ToUniqueStringSlice

tools/list/list.go:111–140  ·  view source on GitHub ↗

ToUniqueStringSlice casts `value` to a slice of non-zero unique strings.

(value any)

Source from the content-addressed store, hash-verified

109
110// ToUniqueStringSlice casts `value` to a slice of non-zero unique strings.
111func ToUniqueStringSlice(value any) (result []string) {
112 switch val := value.(type) {
113 case nil:
114 // nothing to cast
115 case []string:
116 result = val
117 case string:
118 if val == "" {
119 break
120 }
121
122 // check if it is a json encoded array of strings
123 if strings.Contains(val, "[") {
124 if err := json.Unmarshal([]byte(val), &result); err != nil {
125 // not a json array, just add the string as single array element
126 result = append(result, val)
127 }
128 } else {
129 // just add the string as single array element
130 result = append(result, val)
131 }
132 case json.Marshaler: // eg. JSONArray
133 raw, _ := val.MarshalJSON()
134 _ = json.Unmarshal(raw, &result)
135 default:
136 result = cast.ToStringSlice(value)
137 }
138
139 return NonzeroUniques(result)
140}
141
142// ToChunks splits list into chunks.
143//

Callers 15

TestToUniqueStringSliceFunction · 0.92
normalizeValueMethod · 0.92
DriverValueMethod · 0.92
ValidateValueMethod · 0.92
appendValueMethod · 0.92
prependValueMethod · 0.92
subtractValueMethod · 0.92
normalizeExpandsFunction · 0.92
TestFileFieldInterceptFunction · 0.92
processFilesToDeleteMethod · 0.92

Calls 2

NonzeroUniquesFunction · 0.85
MarshalJSONMethod · 0.45

Tested by 3

TestToUniqueStringSliceFunction · 0.74
TestFileFieldInterceptFunction · 0.74
TestExpandRecordsFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…