Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)
re.h File Reference
#include "ruby/internal/config.h"
#include <stdio.h>
#include "ruby/onigmo.h"
#include "ruby/regex.h"
#include "ruby/internal/core/rmatch.h"
#include "ruby/internal/dllexport.h"

Go to the source code of this file.

Functions

VALUE rb_reg_regcomp (VALUE str)
 Creates a new instance of rb_cRegexp.
 
long rb_reg_search (VALUE re, VALUE str, long pos, int dir)
 Runs the passed regular expression over the passed string.
 
VALUE rb_reg_regsub (VALUE repl, VALUE src, struct re_registers *regs, VALUE rexp)
 Substitution.
 
long rb_reg_adjust_startpos (VALUE re, VALUE str, long pos, int dir)
 Tell us if this is a wrong idea, but it seems this function has no usage at all.
 
VALUE rb_reg_quote (VALUE str)
 Escapes any characters that would have special meaning in a regular expression.
 
regex_trb_reg_prepare_re (VALUE re, VALUE str)
 Exercises various checks and preprocesses so that the given regular expression can be applied to the given string.
 
OnigPosition rb_reg_onig_match (VALUE re, VALUE str, OnigPosition(*match)(regex_t *reg, VALUE str, struct re_registers *regs, void *args), void *args, struct re_registers *regs)
 Runs a regular expression match using function match.
 
int rb_reg_region_copy (struct re_registers *dst, const struct re_registers *src)
 Duplicates a match data.
 

Detailed Description

Author
$Author$
Date
Thu Sep 30 14:18:32 JST 1993

Definition in file re.h.

Function Documentation

◆ rb_reg_adjust_startpos()

long rb_reg_adjust_startpos ( VALUE re,
VALUE str,
long pos,
int dir )

Tell us if this is a wrong idea, but it seems this function has no usage at all.

Just remains here for theoretical backwards compatibility.

Parameters
[in]reRegular expression to execute.
[in]strTarget string to search.
[in]posOffset in str to start searching, in bytes.
[in]dirpos' direction; 0 means left-to-right, 1 for the opposite.
Returns
Adjusted nearest offset to pos inside of str, where is a character boundary.

Definition at line 1691 of file re.c.

◆ rb_reg_onig_match()

OnigPosition rb_reg_onig_match ( VALUE re,
VALUE str,
OnigPosition(* match )(regex_t *reg, VALUE str, struct re_registers *regs, void *args),
void * args,
struct re_registers * regs )

Runs a regular expression match using function match.

Performs preparation, error handling, and memory cleanup.

Parameters
[in]reTarget regular expression.
[in]strWhat re is about to run on.
[in]matchThe function to run to match str against re.
[in]argsPointer to arguments to pass into match.
[out]regsRegisters on a successful match.
Exceptions
rb_eArgError`re` does not fit for `str`.
rb_eEncCompatError`re` and `str` are incompatible.
rb_eRegexpError`re` is malformed.
Returns
Match position on a successful match, ONIG_MISMATCH otherwise.

Definition at line 1655 of file re.c.

◆ rb_reg_prepare_re()

regex_t * rb_reg_prepare_re ( VALUE re,
VALUE str )

Exercises various checks and preprocesses so that the given regular expression can be applied to the given string.

The preprocess here includes (but not limited to) for instance encoding conversion.

Parameters
[in]reTarget regular expression.
[in]strWhat re is about to run on.
Exceptions
rb_eArgError`re` does not fit for `str`.
rb_eEncCompatError`re` and `str` are incompatible.
rb_eRegexpError`re` is malformed.
Returns
A preprocessesed pattern buffer ready to be applied to str.
Note
The return value is manages by our GC. Don't free.

Definition at line 1587 of file re.c.

Referenced by rb_reg_onig_match().

◆ rb_reg_quote()

VALUE rb_reg_quote ( VALUE str)

Escapes any characters that would have special meaning in a regular expression.

Parameters
[in]strTarget string to escape.
Returns
A copy of str whose contents are escaped.

Definition at line 4030 of file re.c.

Referenced by rb_reg_quote().

◆ rb_reg_regcomp()

VALUE rb_reg_regcomp ( VALUE str)

Creates a new instance of rb_cRegexp.

It can be seen as a specialised version of rb_reg_new_str() where it does not take options.

Parameters
[in]strSource code in String.
Returns
Allocated new instance of rb_cRegexp.

Definition at line 3431 of file re.c.

◆ rb_reg_region_copy()

int rb_reg_region_copy ( struct re_registers * dst,
const struct re_registers * src )

Duplicates a match data.

This is roughly the same as onig_region_copy(), except it tries to GC when there is not enough memory.

Parameters
[out]dstTarget registers to fill.
[in]srcSource registers to duplicate.
Exceptions
rb_eNoMemErrorNot enough memory.
Return values
0Successful
ONIGERR_MEMORYNot enough memory, even after GC (unlikely).
Postcondition
dst has identical contents to src.

Definition at line 984 of file re.c.

◆ rb_reg_regsub()

VALUE rb_reg_regsub ( VALUE repl,
VALUE src,
struct re_registers * regs,
VALUE rexp )

Substitution.

This is basically the implementation of String#sub. Also String#gsub repeatedly calls this function.

Parameters
[in]replReplacement string, e.g. "\\1\\2"
[in]srcSource string, to be replaced.
[in]regsMatched data generated by applying rexp to src.
[in]rexpRegular expression.
Returns
A substituted string.

Definition at line 4394 of file re.c.

Referenced by rb_reg_regsub().

◆ rb_reg_search()

long rb_reg_search ( VALUE re,
VALUE str,
long pos,
int dir )

Runs the passed regular expression over the passed string.

Unlike rb_reg_search() this function also takes position and direction of the search, which make it possible for this function to run from in middle of the string.

Parameters
[in]reRegular expression to execute.
[in]strTarget string to search.
[in]posOffset in str to start searching, in bytes.
[in]dirpos' direction; 0 means left-to-right, 1 for the opposite.
Exceptions
rb_eArgError`re` is broken.
rb_eRegexpError`re` is malformed.
Return values
-1Match failed.
otherwiseOffset of first such byte where match happened.
Postcondition
Regexp.last_match is updated.
$&, $~, etc., are updated.

Definition at line 1796 of file re.c.

Referenced by rb_reg_match2().