MCPcopy Create free account
hub / github.com/docker/cli / stringSliceReplaceAt

Function stringSliceReplaceAt

cmd/docker/aliases_utils.go:23–32  ·  view source on GitHub ↗

stringSliceReplaceAt replaces the sub-slice find, with the sub-slice replace, in the string slice s, returning a new slice and a boolean indicating if the replacement happened. requireIdx is the index at which old needs to be found at (or -1 to disregard that).

(s, find, replace []string, requireIndex int)

Source from the content-addressed store, hash-verified

21// slice s, returning a new slice and a boolean indicating if the replacement happened.
22// requireIdx is the index at which old needs to be found at (or -1 to disregard that).
23func stringSliceReplaceAt(s, find, replace []string, requireIndex int) ([]string, bool) {
24 idx := stringSliceIndex(s, find)
25 if (requireIndex != -1 && requireIndex != idx) || idx == -1 {
26 return s, false
27 }
28 out := append([]string{}, s[:idx]...)
29 out = append(out, replace...)
30 out = append(out, s[idx+len(find):]...)
31 return out, true
32}

Callers 3

processAliasesFunction · 0.85
TestStringSliceReplaceAtFunction · 0.85
forwardBuilderFunction · 0.85

Calls 1

stringSliceIndexFunction · 0.85

Tested by 1

TestStringSliceReplaceAtFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…