(l *State, isFind bool)
| 18 | } |
| 19 | |
| 20 | func findHelper(l *State, isFind bool) int { |
| 21 | s, p := CheckString(l, 1), CheckString(l, 2) |
| 22 | init := relativePosition(OptInteger(l, 3, 1), len(s)) |
| 23 | if init < 1 { |
| 24 | init = 1 |
| 25 | } else if init > len(s)+1 { |
| 26 | l.PushNil() |
| 27 | return 1 |
| 28 | } |
| 29 | isPlain := l.TypeOf(4) == TypeNone || l.ToBoolean(4) |
| 30 | if isFind && (isPlain || !strings.ContainsAny(p, "^$*+?.([%-")) { |
| 31 | if start := strings.Index(s[init-1:], p); start >= 0 { |
| 32 | l.PushInteger(start + init) |
| 33 | l.PushInteger(start + init + len(p) - 1) |
| 34 | return 2 |
| 35 | } |
| 36 | } else { |
| 37 | l.assert(false) // TODO implement pattern matching |
| 38 | } |
| 39 | l.PushNil() |
| 40 | return 1 |
| 41 | } |
| 42 | |
| 43 | func scanFormat(l *State, fs string) string { |
| 44 | i := 0 |
no test coverage detected