Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)
|
#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_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. | |
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. |
Definition in file re.h.
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.
[in] | re | Regular expression to execute. |
[in] | str | Target string to search. |
[in] | pos | Offset in str to start searching, in bytes. |
[in] | dir | pos' direction; 0 means left-to-right, 1 for the opposite. |
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.
[in] | re | Target regular expression. |
[in] | str | What re is about to run on. |
[in] | match | The function to run to match str against re. |
[in] | args | Pointer to arguments to pass into match. |
[out] | regs | Registers on a successful match. |
rb_eArgError | `re` does not fit for `str`. |
rb_eEncCompatError | `re` and `str` are incompatible. |
rb_eRegexpError | `re` is malformed. |
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.
[in] | re | Target regular expression. |
[in] | str | What re is about to run on. |
rb_eArgError | `re` does not fit for `str`. |
rb_eEncCompatError | `re` and `str` are incompatible. |
rb_eRegexpError | `re` is malformed. |
Definition at line 1635 of file re.c.
Referenced by rb_reg_onig_match().
Escapes any characters that would have special meaning in a regular expression.
[in] | str | Target string to escape. |
Definition at line 4078 of file re.c.
Referenced by rb_reg_quote().
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.
[in] | str | Source code in String. |
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.
[out] | dst | Target registers to fill. |
[in] | src | Source registers to duplicate. |
rb_eNoMemError | Not enough memory. |
0 | Successful |
ONIGERR_MEMORY | Not enough memory, even after GC (unlikely). |
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.
[in] | repl | Replacement string, e.g. "\\1\\2" |
[in] | src | Source string, to be replaced. |
[in] | regs | Matched data generated by applying rexp to src. |
[in] | rexp | Regular expression. |
Definition at line 4442 of file re.c.
Referenced by rb_reg_regsub().
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.
[in] | re | Regular expression to execute. |
[in] | str | Target string to search. |
[in] | pos | Offset in str to start searching, in bytes. |
[in] | dir | pos' direction; 0 means left-to-right, 1 for the opposite. |
rb_eArgError | `re` is broken. |
rb_eRegexpError | `re` is malformed. |
-1 | Match failed. |
otherwise | Offset of first such byte where match happened. |
Definition at line 1844 of file re.c.
Referenced by rb_reg_match2().