(args ...vector.Any)
| 18 | } |
| 19 | |
| 20 | func (r *Regexp) Call(args ...vector.Any) vector.Any { |
| 21 | if vec, ok := expr.CheckForNullThenError(args); ok { |
| 22 | return vec |
| 23 | } |
| 24 | args = underAll(args) |
| 25 | regVec, inputVec := args[0], args[1] |
| 26 | if regVec.Type().ID() != super.IDString { |
| 27 | return vector.NewWrappedError(r.sctx, "regexp: string required for first arg", args[0]) |
| 28 | } |
| 29 | if inputVec.Type().ID() != super.IDString { |
| 30 | return vector.NewWrappedError(r.sctx, "regexp: string required for second arg", args[1]) |
| 31 | } |
| 32 | errMsg := vector.NewStringEmpty(0) |
| 33 | var errs []uint32 |
| 34 | inner := vector.NewStringEmpty(0) |
| 35 | out := vector.NewArray(r.sctx.LookupTypeArray(super.TypeString), []uint32{0}, inner) |
| 36 | for i := range regVec.Len() { |
| 37 | re := vector.StringValue(regVec, i) |
| 38 | if r.restr != re { |
| 39 | r.restr = re |
| 40 | r.re, r.err = regexp.Compile(r.restr) |
| 41 | } |
| 42 | if r.err != nil { |
| 43 | errMsg.Append(regexpErrMsg("regexp", r.err)) |
| 44 | errs = append(errs, i) |
| 45 | continue |
| 46 | } |
| 47 | s := vector.StringValue(inputVec, i) |
| 48 | match := r.re.FindStringSubmatch(s) |
| 49 | for _, b := range match { |
| 50 | inner.Append(b) |
| 51 | } |
| 52 | out.Offsets = append(out.Offsets, inner.Len()) |
| 53 | } |
| 54 | c := vector.NewCombiner(out) |
| 55 | if len(errs) > 0 { |
| 56 | c.Add(errs, vector.NewVecWrappedError(r.sctx, errMsg, vector.Pick(regVec, errs))) |
| 57 | } |
| 58 | return c.Result() |
| 59 | } |
| 60 | |
| 61 | type RegexpReplace struct { |
| 62 | sctx *super.Context |
nothing calls this directly
no test coverage detected