(target, regexStr ref.Val)
| 293 | } |
| 294 | |
| 295 | func extractAll(target, regexStr ref.Val) ref.Val { |
| 296 | t := string(target.(types.String)) |
| 297 | r := string(regexStr.(types.String)) |
| 298 | re, err := regexp.Compile(r) |
| 299 | if err != nil { |
| 300 | return types.WrapErr(err) |
| 301 | } |
| 302 | |
| 303 | groupCount := len(re.SubexpNames()) - 1 |
| 304 | if groupCount > 1 { |
| 305 | return types.WrapErr(fmt.Errorf("regular expression has more than one capturing group: %q", r)) |
| 306 | } |
| 307 | |
| 308 | matches := re.FindAllStringSubmatch(t, -1) |
| 309 | result := make([]string, 0, len(matches)) |
| 310 | if len(matches) == 0 { |
| 311 | return types.NewStringList(types.DefaultTypeAdapter, result) |
| 312 | } |
| 313 | |
| 314 | if groupCount != 1 { |
| 315 | for _, match := range matches { |
| 316 | result = append(result, match[0]) |
| 317 | } |
| 318 | return types.NewStringList(types.DefaultTypeAdapter, result) |
| 319 | } |
| 320 | |
| 321 | for _, match := range matches { |
| 322 | if match[1] != "" { |
| 323 | result = append(result, match[1]) |
| 324 | } |
| 325 | } |
| 326 | return types.NewStringList(types.DefaultTypeAdapter, result) |
| 327 | } |
| 328 | |
| 329 | func estimateRegexSearchCost(c cost.Estimator, args []cost.AstNode) (cost.SizeEstimate, cost.CostEstimate) { |
| 330 | targetSize := cost.EstimateSize(c, args[0]) |
nothing calls this directly
no test coverage detected