(str *string, pattern string, repl func(submatches ...string) string)
| 173 | } |
| 174 | |
| 175 | func ReplaceOnce(str *string, pattern string, repl func(submatches ...string) string) { |
| 176 | re := regexp.MustCompile(pattern) |
| 177 | firstMatch := true |
| 178 | *str = re.ReplaceAllStringFunc(*str, func(match string) string { |
| 179 | if firstMatch { |
| 180 | firstMatch = false |
| 181 | submatches := re.FindStringSubmatch(match) |
| 182 | if submatches != nil { |
| 183 | return repl(submatches...) |
| 184 | } |
| 185 | } |
| 186 | return match |
| 187 | }) |
| 188 | } |
| 189 | |
| 190 | func ReplaceOnceWithPriority(str *string, patterns []string, repl func(index int, submatches ...string) string) { |
| 191 | for i, pattern := range patterns { |
no outgoing calls
no test coverage detected