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

Function strMatch

stringlib.go:353–390  ·  view source on GitHub ↗
(L *LState)

Source from the content-addressed store, hash-verified

351}
352
353func strMatch(L *LState) int {
354 str := L.CheckString(1)
355 pattern := L.CheckString(2)
356 offset := L.OptInt(3, 1)
357 l := len(str)
358 if offset < 0 {
359 offset = l + offset + 1
360 }
361 offset--
362 if offset < 0 {
363 offset = 0
364 }
365
366 mds, err := pm.Find(pattern, unsafeFastStringToReadOnlyBytes(str), offset, 1)
367 if err != nil {
368 L.RaiseError(err.Error())
369 }
370 if len(mds) == 0 {
371 L.Push(LNil)
372 return 0
373 }
374 md := mds[0]
375 nsubs := md.CaptureLength() / 2
376 switch nsubs {
377 case 1:
378 L.Push(LString(str[md.Capture(0):md.Capture(1)]))
379 return 1
380 default:
381 for i := 2; i < md.CaptureLength(); i += 2 {
382 if md.IsPosCapture(i) {
383 L.Push(LNumber(md.Capture(i)))
384 } else {
385 L.Push(LString(str[md.Capture(i):md.Capture(i+1)]))
386 }
387 }
388 return nsubs - 1
389 }
390}
391
392func strRep(L *LState) int {
393 str := L.CheckString(1)

Callers

nothing calls this directly

Calls 12

FindFunction · 0.92
LStringTypeAlias · 0.85
LNumberTypeAlias · 0.85
CheckStringMethod · 0.80
OptIntMethod · 0.80
CaptureLengthMethod · 0.80
CaptureMethod · 0.80
IsPosCaptureMethod · 0.80
ErrorMethod · 0.65
PushMethod · 0.65
RaiseErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…