(L *LState)
| 88 | } |
| 89 | |
| 90 | func strFind(L *LState) int { |
| 91 | str := L.CheckString(1) |
| 92 | pattern := L.CheckString(2) |
| 93 | if len(pattern) == 0 { |
| 94 | L.Push(LNumber(1)) |
| 95 | L.Push(LNumber(0)) |
| 96 | return 2 |
| 97 | } |
| 98 | init := luaIndex2StringIndex(str, L.OptInt(3, 1), true) |
| 99 | plain := false |
| 100 | if L.GetTop() == 4 { |
| 101 | plain = LVAsBool(L.Get(4)) |
| 102 | } |
| 103 | |
| 104 | if plain { |
| 105 | pos := strings.Index(str[init:], pattern) |
| 106 | if pos < 0 { |
| 107 | L.Push(LNil) |
| 108 | return 1 |
| 109 | } |
| 110 | L.Push(LNumber(init+pos) + 1) |
| 111 | L.Push(LNumber(init + pos + len(pattern))) |
| 112 | return 2 |
| 113 | } |
| 114 | |
| 115 | mds, err := pm.Find(pattern, unsafeFastStringToReadOnlyBytes(str), init, 1) |
| 116 | if err != nil { |
| 117 | L.RaiseError(err.Error()) |
| 118 | } |
| 119 | if len(mds) == 0 { |
| 120 | L.Push(LNil) |
| 121 | return 1 |
| 122 | } |
| 123 | md := mds[0] |
| 124 | L.Push(LNumber(md.Capture(0) + 1)) |
| 125 | L.Push(LNumber(md.Capture(1))) |
| 126 | for i := 2; i < md.CaptureLength(); i += 2 { |
| 127 | if md.IsPosCapture(i) { |
| 128 | L.Push(LNumber(md.Capture(i))) |
| 129 | } else { |
| 130 | L.Push(LString(str[md.Capture(i):md.Capture(i+1)])) |
| 131 | } |
| 132 | } |
| 133 | return md.CaptureLength()/2 + 1 |
| 134 | } |
| 135 | |
| 136 | func strFormat(L *LState) int { |
| 137 | str := L.CheckString(1) |
nothing calls this directly
no test coverage detected
searching dependent graphs…