Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
findall.c File Reference

Implements the OP_PCRE2_FINDALL opcode (conditional build). More...

Go to the source code of this file.

Functions

 free_value (a)
 free_value (b)
 free_value (c)
 push_value (vm, make_array_from_values(NULL, 0))

Variables

case OP_PCRE2_FINDALL
Value b = pop_value(vm)
Value c = pop_value(vm)
 break

Detailed Description

Implements the OP_PCRE2_FINDALL opcode (conditional build).

Finds all non-overlapping matches of a PCRE2 pattern in a subject string and returns an array of maps describing each match when FUN_WITH_PCRE2 is enabled. When PCRE2 support is disabled at build time, the opcode falls back to returning an empty array.

Definition in file findall.c.

Function Documentation

◆ free_value() [1/3]

free_value(a)

◆ free_value() [2/3]

free_value(b)

◆ free_value() [3/3]

free_value(c)

◆ push_value()

push_value(vm,
make_array_from_values(NULL, 0) )

Variable Documentation

◆ b

Value b = pop_value(vm)

Definition at line 131 of file findall.c.

◆ break

break

Definition at line 137 of file findall.c.

◆ c

Value c = pop_value(vm)

Definition at line 133 of file findall.c.

◆ OP_PCRE2_FINDALL

case OP_PCRE2_FINDALL

OP_PCRE2_FINDALL: (pattern:any, text:any, flags:int|bool=0) -> array(map)

Behavior when FUN_WITH_PCRE2 is enabled:

  • Pops three arguments from the VM stack: pattern, text, flags.
    • pattern and text are converted to strings using value_to_string_alloc().
    • flags bits map to PCRE2 options:
      • 1 = PCRE2_CASELESS (I)
      • 2 = PCRE2_MULTILINE (M)
      • 4 = PCRE2_DOTALL (S)
      • 8 = PCRE2_UTF (U)
      • 16 = PCRE2_EXTENDED (X)
  • Compiles the pattern and scans the subject for all non-overlapping matches. For each match, pushes into the result array a map with keys:
    • "full": matched substring (group 0)
    • "start": start index (int)
    • "end": end index (int, exclusive)
    • "groups": array of captured group strings (excluding group 0)
  • On compilation error or allocation failure, returns an empty array.

Behavior when FUN_WITH_PCRE2 is disabled:

  • Pops three values and returns an empty array.

Definition at line 45 of file findall.c.