MCPcopy Index your code
hub / github.com/yuin/gopher-lua / strGsubFunc

Function strGsubFunc

stringlib.go:267–293  ·  view source on GitHub ↗
(L *LState, str string, repl *LFunction, matches []*pm.MatchData)

Source from the content-addressed store, hash-verified

265}
266
267func 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
295type strMatchData struct {
296 str string

Callers 1

strGsubFunction · 0.85

Calls 12

LNumberTypeAlias · 0.85
LStringTypeAlias · 0.85
capturedStringFunction · 0.85
LVIsFalseFunction · 0.85
LVAsStringFunction · 0.85
strGsubDoReplaceFunction · 0.85
CaptureMethod · 0.80
CaptureLengthMethod · 0.80
IsPosCaptureMethod · 0.80
PushMethod · 0.65
PopMethod · 0.65
CallMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…