Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Typedefs | Functions | Variables
re.c File Reference
`#include "ruby/encoding.h"`
`#include "ruby/re.h"`
`#include "ruby/util.h"`
`#include "internal.h"`
`#include "regint.h"`
`#include "encindex.h"`
`#include <ctype.h>`

Go to the source code of this file.

## Data Structures
struct | pair_t
struct | backref_name_tag

## Macros
#define | errcpy(err, msg) strlcpy((err), (msg), ONIG_MAX_ERROR_MESSAGE_LEN)
#define | BEG(no) (regs->beg[(no)])
#define | END(no) (regs->end[(no)])
#define | VALUE_MAX ((VALUE)~(VALUE)0)
#define | REG_LITERAL FL_USER5
#define | REG_ENCODING_NONE FL_USER6
#define | KCODE_FIXED FL_USER4
#define | ARG_REG_OPTION_MASK (ONIG_OPTION_IGNORECASE|ONIG_OPTION_MULTILINE|ONIG_OPTION_EXTEND)
#define | ARG_ENCODING_FIXED 16
#define | ARG_ENCODING_NONE 32
#define | MATCH_BUSY FL_USER2
#define | NAME_TO_NUMBER(regs, re, name, name_ptr, name_end)
#define | ASCGET(s, e, cl) (acompat ? (*(cl)=1,ISASCII((s)[0])?(s)[0]:-1) : rb_enc_ascget((s), (e), (cl), str_enc))

## Typedefs
typedef char | onig_errmsg_buffer[ONIG_MAX_ERROR_MESSAGE_LEN]

## Functions
int | rb_memcicmp (const void *x, const void *y, long len)
long | rb_memsearch (const void *x0, long m, const void *y0, long n, rb_encoding *enc)
int | rb_char_to_option_kcode (int c, int *option, int *kcode)
| NORETURN (static void rb_reg_raise(const char *s, long len, const char *err, VALUE re))
| NORETURN (static void rb_enc_reg_raise(const char *s, long len, rb_encoding *enc, int options, const char *err))
| NORETURN (static void rb_reg_raise_str(VALUE str, int options, const char *err))
int | rb_reg_region_copy (struct re_registers *to, const struct re_registers *from)
int | rb_reg_backref_number (VALUE match, VALUE backref)
void | rb_match_busy (VALUE match)
void | rb_match_unbusy (VALUE match)
int | rb_match_count (VALUE match)
int | rb_match_nth_defined (int nth, VALUE match)
void | rb_backref_set_string (VALUE string, long pos, long len)
| NORETURN (static void reg_enc_error(VALUE re, VALUE str))
regex_t * | rb_reg_prepare_re0 (VALUE re, VALUE str, onig_errmsg_buffer err)
regex_t * | rb_reg_prepare_re (VALUE re, VALUE str)
long | rb_reg_adjust_startpos (VALUE re, VALUE str, long pos, int reverse)
long | rb_reg_search0 (VALUE re, VALUE str, long pos, int reverse, int set_backref_str)
long | rb_reg_search (VALUE re, VALUE str, long pos, int reverse)
bool | rb_reg_start_with_p (VALUE re, VALUE str)
VALUE | rb_reg_nth_defined (int nth, VALUE match)
VALUE | rb_reg_nth_match (int nth, VALUE match)
VALUE | rb_reg_last_match (VALUE match)
VALUE | rb_reg_match_pre (VALUE match)
VALUE | rb_reg_match_post (VALUE match)
VALUE | rb_reg_match_last (VALUE match)
| NORETURN (static void name_to_backref_error(VALUE name))
VALUE | rb_reg_check_preprocess (VALUE str)
VALUE | rb_reg_alloc (void)
VALUE | rb_reg_new_str (VALUE s, int options)
VALUE | rb_reg_init_str (VALUE re, VALUE s, int options)
MJIT_FUNC_EXPORTED VALUE | rb_reg_new_ary (VALUE ary, int opt)
VALUE | rb_enc_reg_new (const char *s, long len, rb_encoding *enc, int options)
VALUE | rb_reg_new (const char *s, long len, int options)
VALUE | rb_reg_compile (VALUE str, int options, const char *sourcefile, int sourceline)
VALUE | rb_reg_regcomp (VALUE str)
VALUE | rb_reg_match (VALUE re, VALUE str)
VALUE | rb_reg_eqq (VALUE re, VALUE str)
VALUE | rb_reg_match2 (VALUE re)
VALUE | rb_reg_match_p (VALUE re, VALUE str, long pos)
VALUE | rb_reg_quote (VALUE str)
int | rb_reg_options (VALUE re)
VALUE | rb_check_regexp_type (VALUE re)
VALUE | rb_reg_regsub (VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
void | Init_Regexp (void)

## Variables
VALUE | rb_eRegexpError
VALUE | rb_cMatch
VALUE | rb_cRegexp

## Macro Definition Documentation

## ◆ ARG_ENCODING_FIXED

#define ARG_ENCODING_FIXED 16

Definition at line 282 of file re.c.

## ◆ ARG_ENCODING_NONE

#define ARG_ENCODING_NONE 32

Definition at line 283 of file re.c.

## ◆ ARG_REG_OPTION_MASK

#define ARG_REG_OPTION_MASK (ONIG_OPTION_IGNORECASE|ONIG_OPTION_MULTILINE|ONIG_OPTION_EXTEND)

Definition at line 280 of file re.c.

## ◆ ASCGET

#define ASCGET | ( |  | s,
|  |  | e,
|  |  | cl
| ) |  | (acompat ? (*(cl)=1,ISASCII((s)[0])?(s)[0]:-1) : rb_enc_ascget((s), (e), (cl), str_enc))

## ◆ BEG

#define BEG | ( |  | no | ) | (regs->beg[(no)])

Definition at line 25 of file re.c.

## ◆ END

#define END | ( |  | no | ) | (regs->end[(no)])

Definition at line 26 of file re.c.

## ◆ errcpy

#define errcpy | ( |  | err,
|  |  | msg
| ) |  | strlcpy((err), (msg), ONIG_MAX_ERROR_MESSAGE_LEN)

Definition at line 23 of file re.c.

## ◆ KCODE_FIXED

#define KCODE_FIXED FL_USER4

Definition at line 278 of file re.c.

## ◆ MATCH_BUSY

#define MATCH_BUSY FL_USER2

Definition at line 1284 of file re.c.

## ◆ NAME_TO_NUMBER

#define NAME_TO_NUMBER | ( |  | regs,
|  |  | re,
|  |  | name,
|  |  | name_ptr,
|  |  | name_end
| ) |  |

Value:
(NIL_P(re) ? 0 : \
!rb_enc_compatible(RREGEXP_SRC(re), (name)) ? 0 : \
name_to_backref_number((regs), (re), (name_ptr), (name_end)))

Definition at line 1920 of file re.c.

## ◆ REG_ENCODING_NONE

#define REG_ENCODING_NONE FL_USER6

Definition at line 276 of file re.c.

## ◆ REG_LITERAL

#define REG_LITERAL FL_USER5

Definition at line 275 of file re.c.

## ◆ VALUE_MAX

#define VALUE_MAX ((VALUE)~(VALUE)0)

## Typedef Documentation

## ◆ onig_errmsg_buffer

typedef char onig_errmsg_buffer[ONIG_MAX_ERROR_MESSAGE_LEN]

Definition at line 22 of file re.c.

## Function Documentation

## ◆ Init_Regexp()

void Init_Regexp | ( | void |  | ) |

Definition at line 4019 of file re.c.

References ONIG_ENCODING_ASCII, onig_set_warn_func(), onigenc_set_default_encoding(), rb_define_class(), rb_eRegexpError, and rb_eStandardError.

## ◆ NORETURN() [1/5]

NORETURN | ( | static void | name_to_backref_errorVALUE name | ) |

## ◆ NORETURN() [2/5]

NORETURN | ( | static void | rb_enc_reg_raiseconst char *s, long len, rb_encoding *enc, int options, const char *err | ) |

## ◆ NORETURN() [3/5]

NORETURN | ( | static void | rb_reg_raiseconst char *s, long len, const char *err, VALUE re | ) |

## ◆ NORETURN() [4/5]

NORETURN | ( | static void | rb_reg_raise_strVALUE str, int options, const char *err | ) |

## ◆ NORETURN() [5/5]

NORETURN | ( | static void | reg_enc_errorVALUE re, VALUE str | ) |

## ◆ rb_backref_set_string()

void rb_backref_set_string | ( | VALUE | string,
|  | long | pos,
|  | long | len
| ) |  |

Definition at line 1340 of file re.c.

## ◆ rb_char_to_option_kcode()

int rb_char_to_option_kcode | ( | int | c,
|  | int * | option,
|  | int * | kcode
| ) |  |

Definition at line 319 of file re.c.

References ARG_ENCODING_NONE, ENCINDEX_EUC_JP, ENCINDEX_Windows_31J, rb_ascii8bit_encindex(), and rb_utf8_encindex().

## ◆ rb_check_regexp_type()

VALUE rb_check_regexp_type | ( | VALUE | re | ) |

Definition at line 3590 of file re.c.

References rb_check_convert_type(), and T_REGEXP.

## ◆ rb_enc_reg_new()

VALUE rb_enc_reg_new | ( | const char * | s,
|  | long | len,
|  | rb_encoding * | enc,
|  | int | options
| ) |  |

Definition at line 2932 of file re.c.

## ◆ rb_match_busy()

void rb_match_busy | ( | VALUE | match | ) |

Definition at line 1287 of file re.c.

## ◆ rb_match_count()

int rb_match_count | ( | VALUE | match | ) |

Definition at line 1299 of file re.c.

## ◆ rb_match_nth_defined()

int rb_match_nth_defined | ( | int | nth,
|  | VALUE | match
| ) |  |

Definition at line 1309 of file re.c.

## ◆ rb_match_unbusy()

void rb_match_unbusy | ( | VALUE | match | ) |

Definition at line 1293 of file re.c.

## ◆ rb_memcicmp()

int rb_memcicmp | ( | const void * | x,
|  | const void * | y,
|  | long | len
| ) |  |

Definition at line 80 of file re.c.

References len.

## ◆ rb_memsearch()

long rb_memsearch | ( | const void * | x0,
|  | long | m,
|  | const void * | y0,
|  | long | n,
|  | rb_encoding * | enc
| ) |  |

Definition at line 239 of file re.c.

References LIKELY, memchr(), memcmp(), n, rb_enc_mbminlen, SIZEOF_VALUE, and y0().

## ◆ rb_reg_adjust_startpos()

long rb_reg_adjust_startpos | ( | VALUE | re,
|  | VALUE | str,
|  | long | pos,
|  | int | reverse
| ) |  |

Definition at line 1498 of file re.c.

References range, rb_encoding, and UChar.

## ◆ rb_reg_alloc()

VALUE rb_reg_alloc | ( | void |  | ) |

Definition at line 2888 of file re.c.

## ◆ rb_reg_backref_number()

int rb_reg_backref_number | ( | VALUE | match,
|  | VALUE | backref
| ) |  |

Definition at line 1173 of file re.c.

## ◆ rb_reg_check_preprocess()

VALUE rb_reg_check_preprocess | ( | VALUE | str | ) |

Definition at line 2706 of file re.c.

References buf, err, rb_enc_get(), rb_encoding, RSTRING_LEN, RSTRING_PTR, str, and StringValue().

## ◆ rb_reg_compile()

VALUE rb_reg_compile | ( | VALUE | str,
|  | int | options,
|  | const char * | sourcefile,
|  | int | sourceline
| ) |  |

Definition at line 2952 of file re.c.

## ◆ rb_reg_eqq()

VALUE rb_reg_eqq | ( | VALUE | re,
|  | VALUE | str
| ) |  |

Definition at line 3209 of file re.c.

References str.

## ◆ rb_reg_init_str()

VALUE rb_reg_init_str | ( | VALUE | re,
|  | VALUE | s,
|  | int | options
| ) |  |

Definition at line 2900 of file re.c.

## ◆ rb_reg_last_match()

VALUE rb_reg_last_match | ( | VALUE | match | ) |

Definition at line 1731 of file re.c.

## ◆ rb_reg_match()

VALUE rb_reg_match | ( | VALUE | re,
|  | VALUE | str
| ) |  |

Definition at line 3179 of file re.c.

## ◆ rb_reg_match2()

VALUE rb_reg_match2 | ( | VALUE | re | ) |

Definition at line 3238 of file re.c.

References LONG2FIX, Qnil, rb_backref_set(), rb_lastline_get(), rb_reg_search(), rb_str_sublen(), RB_TYPE_P, and T_STRING.

## ◆ rb_reg_match_last()

VALUE rb_reg_match_last | ( | VALUE | match | ) |

Definition at line 1792 of file re.c.

## ◆ rb_reg_match_p()

VALUE rb_reg_match_p | ( | VALUE | re,
|  | VALUE | str,
|  | long | pos
| ) |  |

Definition at line 3339 of file re.c.

References err.

## ◆ rb_reg_match_post()

VALUE rb_reg_match_post | ( | VALUE | match | ) |

Definition at line 1775 of file re.c.

## ◆ rb_reg_match_pre()

VALUE rb_reg_match_pre | ( | VALUE | match | ) |

Definition at line 1749 of file re.c.

## ◆ rb_reg_new()

VALUE rb_reg_new | ( | const char * | s,
|  | long | len,
|  | int | options
| ) |  |

Definition at line 2946 of file re.c.

## ◆ rb_reg_new_ary()

MJIT_FUNC_EXPORTED VALUE rb_reg_new_ary | ( | VALUE | ary,
|  | int | opt
| ) |  |

Definition at line 2926 of file re.c.

References rb_reg_new_str().

## ◆ rb_reg_new_str()

VALUE rb_reg_new_str | ( | VALUE | s,
|  | int | options
| ) |  |

Definition at line 2894 of file re.c.

Referenced by rb_reg_new_ary().

## ◆ rb_reg_nth_defined()

VALUE rb_reg_nth_defined | ( | int | nth,
|  | VALUE | match
| ) |  |

Definition at line 1688 of file re.c.

## ◆ rb_reg_nth_match()

VALUE rb_reg_nth_match | ( | int | nth,
|  | VALUE | match
| ) |  |

Definition at line 1706 of file re.c.

## ◆ rb_reg_options()

int rb_reg_options | ( | VALUE | re | ) |

Definition at line 3578 of file re.c.

## ◆ rb_reg_prepare_re()

regex_t* rb_reg_prepare_re | ( | VALUE | re,
|  | VALUE | str
| ) |  |

Definition at line 1491 of file re.c.

References err, rb_reg_prepare_re0(), and str.

## ◆ rb_reg_prepare_re0()

regex_t* rb_reg_prepare_re0 | ( | VALUE | re,
|  | VALUE | str,
|  | onig_errmsg_buffer | err
| ) |  |

Definition at line 1453 of file re.c.

References rb_encoding, and RREGEXP_PTR.

Referenced by rb_reg_prepare_re().

## ◆ rb_reg_quote()

VALUE rb_reg_quote | ( | VALUE | str | ) |

Definition at line 3461 of file re.c.

References mbclen, memcpy(), n, rb_enc_ascget(), rb_enc_associate(), rb_enc_copy(), rb_enc_get(), rb_enc_mbcput, rb_enc_str_asciionly_p(), rb_encoding, rb_str_new, rb_str_new3, rb_str_resize(), rb_usascii_encoding(), RSTRING_LEN, RSTRING_PTR, and str.

## ◆ rb_reg_regcomp()

VALUE rb_reg_regcomp | ( | VALUE | str | ) |

Definition at line 2969 of file re.c.

## ◆ rb_reg_region_copy()

int rb_reg_region_copy | ( | struct re_registers * | to,
|  | const struct re_registers * | from
| ) |  |

Definition at line 946 of file re.c.

References re_registers::allocated, onig_region_copy(), ONIGERR_MEMORY, and rb_gc().

## ◆ rb_reg_regsub()

VALUE rb_reg_regsub | ( | VALUE | str,
|  | VALUE | src,
|  | struct re_registers * | regs,
|  | VALUE | regexp
| ) |  |

Definition at line 3775 of file re.c.

References ASCGET, mbclen, n, name, NAME_TO_NUMBER, NIL_P, onig_noname_group_capture_is_active(), rb_enc_asciicompat, rb_enc_get(), rb_enc_str_buf_cat(), rb_encoding, rb_str_buf_new(), rb_str_subseq(), RREGEXP_PTR, RSTRING_LEN, RSTRING_PTR, src, and str.

## ◆ rb_reg_search()

long rb_reg_search | ( | VALUE | re,
|  | VALUE | str,
|  | long | pos,
|  | int | reverse
| ) |  |

Definition at line 1612 of file re.c.

References rb_reg_search0(), and str.

Referenced by rb_reg_match2().

## ◆ rb_reg_search0()

long rb_reg_search0 | ( | VALUE | re,
|  | VALUE | str,
|  | long | pos,
|  | int | reverse,
|  | int | set_backref_str
| ) |  |

Definition at line 1530 of file re.c.

Referenced by rb_reg_search().

## ◆ rb_reg_start_with_p()

bool rb_reg_start_with_p | ( | VALUE | re,
|  | VALUE | str
| ) |  |

Definition at line 1618 of file re.c.

rb_enc_compatible
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
Definition: encoding.c:974
RREGEXP_SRC
#define RREGEXP_SRC(r)
Definition: ruby.h:1119
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
name
const char * name
Definition: nkf.c:208