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...

#include <pcre2.h>
Include dependency graph for findall.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PCRE2_CODE_UNIT_WIDTH   8

Functions

 if (vflags.type==VAL_INT||vflags.type==VAL_BOOL) flags
 free_value (vflags)
 free_value (vtext)
 free_value (vpat)
 if (!pattern||!subject)
 if (flags &1) opt| = PCRE2_MULTILINE
 if (!re)
 while (1)
 pcre2_match_data_free (mdata)
 pcre2_code_free (re)
 free (pattern)
 free (subject)
 push_value (vm, out)

Variables

case OP_PCRE2_FINDALL
Value vtext = pop_value(vm)
Value vpat = pop_value(vm)
int flags = 0
char * pattern = value_to_string_alloc(&vpat)
char * subject = value_to_string_alloc(&vtext)
int errorcode
PCRE2_SIZE erroff
uint32_t opt = 0
pcre2_code * re = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, opt, &errorcode, &erroff, NULL)
pcre2_match_data * mdata = pcre2_match_data_create_from_pattern(re, NULL)
Value out = make_array_from_values(NULL, 0)
size_t subj_len = strlen(subject)
size_t start_off = 0
int gcount = 0
 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.

Macro Definition Documentation

◆ PCRE2_CODE_UNIT_WIDTH

#define PCRE2_CODE_UNIT_WIDTH   8

Definition at line 64 of file findall.c.

Function Documentation

◆ free() [1/2]

free ( pattern )

◆ free() [2/2]

free ( subject )

◆ free_value() [1/3]

free_value ( vflags )

◆ free_value() [2/3]

free_value ( vpat )

◆ free_value() [3/3]

free_value ( vtext )

◆ if() [1/4]

if ( !pattern||! subject)

Definition at line 57 of file findall.c.

◆ if() [2/4]

if ( ! re)

Definition at line 76 of file findall.c.

◆ if() [3/4]

if ( flags & 1) = PCRE2_MULTILINE

◆ if() [4/4]

if ( vflags. type = =VAL_INT||vflags.type==VAL_BOOL)

◆ pcre2_code_free()

pcre2_code_free ( re )

◆ pcre2_match_data_free()

pcre2_match_data_free ( mdata )

◆ push_value()

push_value ( vm ,
out  )

◆ while()

while ( 1 )

Definition at line 87 of file findall.c.

Variable Documentation

◆ break

break

Definition at line 137 of file findall.c.

◆ erroff

PCRE2_SIZE erroff

Definition at line 68 of file findall.c.

◆ errorcode

int errorcode

Definition at line 67 of file findall.c.

◆ flags

int flags = 0

Definition at line 50 of file findall.c.

◆ gcount

int gcount = 0

Definition at line 86 of file findall.c.

◆ mdata

pcre2_match_data* mdata = pcre2_match_data_create_from_pattern(re, NULL)

Definition at line 82 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.

◆ opt

uint32_t opt = 0

Definition at line 69 of file findall.c.

◆ out

Value out = make_array_from_values(NULL, 0)

Definition at line 83 of file findall.c.

◆ pattern

char* pattern = value_to_string_alloc(&vpat)

Definition at line 52 of file findall.c.

◆ re

pcre2_code* re = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, opt, &errorcode, &erroff, NULL)

Definition at line 75 of file findall.c.

◆ start_off

size_t start_off = 0

Definition at line 85 of file findall.c.

◆ subj_len

size_t subj_len = strlen(subject)

Definition at line 84 of file findall.c.

◆ subject

char* subject = value_to_string_alloc(&vtext)

Definition at line 53 of file findall.c.

◆ vpat

Value vpat = pop_value(vm)

Definition at line 49 of file findall.c.

◆ vtext

Value vtext = pop_value(vm)

Definition at line 48 of file findall.c.