(L *LState, str string, repl *LFunction, matches []*pm.MatchData)
| 265 | } |
| 266 | |
| 267 | func strGsubFunc(L *LState, str string, repl *LFunction, matches []*pm.MatchData) string { |
| 268 | infoList := make([]replaceInfo, 0, len(matches)) |
| 269 | for _, match := range matches { |
| 270 | start, end := match.Capture(0), match.Capture(1) |
| 271 | L.Push(repl) |
| 272 | nargs := 0 |
| 273 | if match.CaptureLength() > 2 { // has captures |
| 274 | for i := 2; i < match.CaptureLength(); i += 2 { |
| 275 | if match.IsPosCapture(i) { |
| 276 | L.Push(LNumber(match.Capture(i))) |
| 277 | } else { |
| 278 | L.Push(LString(capturedString(L, match, str, i))) |
| 279 | } |
| 280 | nargs++ |
| 281 | } |
| 282 | } else { |
| 283 | L.Push(LString(capturedString(L, match, str, 0))) |
| 284 | nargs++ |
| 285 | } |
| 286 | L.Call(nargs, 1) |
| 287 | ret := L.reg.Pop() |
| 288 | if !LVIsFalse(ret) { |
| 289 | infoList = append(infoList, replaceInfo{[]int{start, end}, LVAsString(ret)}) |
| 290 | } |
| 291 | } |
| 292 | return strGsubDoReplace(str, infoList) |
| 293 | } |
| 294 | |
| 295 | type strMatchData struct { |
| 296 | str string |
no test coverage detected
searching dependent graphs…