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)
| 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). |
| 23 | func 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 | } |
searching dependent graphs…