Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
test.c File Reference

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

#include <pcre2.h>
Include dependency graph for test.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|
 if (!re)
 pcre2_match_data_free (mdata)
 pcre2_code_free (re)
 free (pattern)
 free (subject)
 push_value (vm, make_int(rc >=0 ? 1 :0))

Variables

case OP_PCRE2_TEST
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)
int rc = pcre2_match(re, (PCRE2_SPTR)subject, (PCRE2_SIZE)strlen(subject), 0, 0, mdata, NULL)
 break

Detailed Description

Implements the OP_PCRE2_TEST opcode (conditional build).

Tests whether a PCRE2 pattern matches a subject string and returns 1 on success or 0 otherwise when FUN_WITH_PCRE2 is enabled. When PCRE2 support is disabled at build time, the opcode always returns 0.

Definition in file test.c.

Macro Definition Documentation

◆ PCRE2_CODE_UNIT_WIDTH

#define PCRE2_CODE_UNIT_WIDTH   8

Definition at line 57 of file test.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 50 of file test.c.

◆ if() [2/4]

if ( ! re)

Definition at line 69 of file test.c.

◆ if() [3/4]

if ( flags & 1)

◆ 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 ,
make_int(rc >=0 ? 1 :0)  )

Variable Documentation

◆ break

break

Definition at line 92 of file test.c.

◆ erroff

PCRE2_SIZE erroff

Definition at line 61 of file test.c.

◆ errorcode

int errorcode

Definition at line 60 of file test.c.

◆ flags

int flags = 0

Definition at line 43 of file test.c.

◆ mdata

pcre2_match_data* mdata = pcre2_match_data_create_from_pattern(re, NULL)

Definition at line 75 of file test.c.

◆ OP_PCRE2_TEST

case OP_PCRE2_TEST

OP_PCRE2_TEST: (pattern:any, text:any, flags:int|bool=0) -> int

Behavior when FUN_WITH_PCRE2 is enabled:

  • Pops: pattern, text, flags. Converts pattern/text to strings.
  • Flags bits:
    • 1 = PCRE2_CASELESS (I)
    • 2 = PCRE2_MULTILINE (M)
    • 4 = PCRE2_DOTALL (S)
    • 8 = PCRE2_UTF (U)
    • 16 = PCRE2_EXTENDED (X)
  • Returns 1 if pcre2_match() returns a non-negative result, else 0.
  • On compile error or allocation failure, returns 0.

Behavior when FUN_WITH_PCRE2 is disabled:

  • Pops three values and returns 0.

Definition at line 38 of file test.c.

◆ opt

uint32_t opt = 0

Definition at line 62 of file test.c.

◆ pattern

char* pattern = value_to_string_alloc(&vpat)

Definition at line 45 of file test.c.

◆ rc

int rc = pcre2_match(re, (PCRE2_SPTR)subject, (PCRE2_SIZE)strlen(subject), 0, 0, mdata, NULL)

Definition at line 76 of file test.c.

◆ re

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

Definition at line 68 of file test.c.

◆ subject

char* subject = value_to_string_alloc(&vtext)

Definition at line 46 of file test.c.

◆ vpat

Value vpat = pop_value(vm)

Definition at line 42 of file test.c.

◆ vtext

Value vtext = pop_value(vm)

Definition at line 41 of file test.c.