MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / RemoveString

Method RemoveString

pkg/util/json/json.go:2404–2430  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

2402}
2403
2404func (j jsonArray) RemoveString(s string) (JSON, bool, error) {
2405 b := NewArrayBuilder(j.Len())
2406 removed := false
2407 for _, el := range j {
2408 // We want to remove only elements of string type.
2409 if el.Type() == StringJSONType {
2410 t, err := el.AsText()
2411 if err != nil {
2412 return nil, false, err
2413 }
2414 if t == nil {
2415 return nil, false, errors.AssertionFailedf("StringJSONType should not be nil here")
2416 }
2417 if *t != s {
2418 b.Add(el)
2419 } else {
2420 removed = true
2421 }
2422 } else {
2423 b.Add(el)
2424 }
2425 }
2426 if removed {
2427 return b.Build(), removed, nil
2428 }
2429 return j, false, nil
2430}
2431
2432func (j jsonObject) RemoveString(s string) (JSON, bool, error) {
2433 idx, ok := findPairIndexByKey(j, s)

Callers

nothing calls this directly

Calls 6

LenMethod · 0.95
AddMethod · 0.95
BuildMethod · 0.95
NewArrayBuilderFunction · 0.85
TypeMethod · 0.65
AsTextMethod · 0.65

Tested by

no test coverage detected