Ruby  3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
rregexp.h
Go to the documentation of this file.
1 #ifndef RBIMPL_RREGEXP_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_RREGEXP_H
25 #include "ruby/internal/cast.h"
28 #include "ruby/internal/value.h"
30 
37 #define RREGEXP(obj) RBIMPL_CAST((struct RRegexp *)(obj))
38 
45 #define RREGEXP_PTR(obj) (RREGEXP(obj)->ptr)
47 #define RREGEXP_SRC RREGEXP_SRC
48 #define RREGEXP_SRC_PTR RREGEXP_SRC_PTR
49 #define RREGEXP_SRC_LEN RREGEXP_SRC_LEN
50 #define RREGEXP_SRC_END RREGEXP_SRC_END
53 struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */
54 
60 struct RRegexp {
61 
63  struct RBasic basic;
64 
72 
74  const VALUE src;
75 
90  unsigned long usecnt;
91 };
92 
102 static inline VALUE
104 {
105  RBIMPL_ASSERT_TYPE(rexp, RUBY_T_REGEXP);
106  VALUE ret = RREGEXP(rexp)->src;
107  RBIMPL_ASSERT_TYPE(ret, RUBY_T_STRING);
108  return ret;
109 }
110 
124 static inline char *
126 {
127  return RSTRING_PTR(RREGEXP_SRC(rexp));
128 }
129 
143 static inline long
145 {
146  return RSTRING_LEN(RREGEXP_SRC(rexp));
147 }
148 
162 static inline char *
164 {
165  return RSTRING_END(RREGEXP_SRC(rexp));
166 }
167 
168 #endif /* RBIMPL_RREGEXP_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition: defines.h:88
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition: pure.h:38
Defines struct RBasic.
#define RREGEXP(obj)
Convenient casting macro.
Definition: rregexp.h:37
static char * RREGEXP_SRC_END(VALUE rexp)
Convenient getter function.
Definition: rregexp.h:163
static VALUE RREGEXP_SRC(VALUE rexp)
Convenient getter function.
Definition: rregexp.h:103
static char * RREGEXP_SRC_PTR(VALUE rexp)
Convenient getter function.
Definition: rregexp.h:125
static long RREGEXP_SRC_LEN(VALUE rexp)
Convenient getter function.
Definition: rregexp.h:144
Defines struct RString.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
Definition: rstring.h:442
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
Definition: rstring.h:416
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
Definition: rstring.h:367
Ruby object's base components.
Definition: rbasic.h:63
Ruby's regular expression.
Definition: rregexp.h:60
struct RBasic basic
Basic part, including flags and class.
Definition: rregexp.h:63
const VALUE src
Source code of this expression.
Definition: rregexp.h:74
unsigned long usecnt
Reference count.
Definition: rregexp.h:90
struct re_pattern_buffer * ptr
The pattern buffer.
Definition: rregexp.h:71
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40
Defines enum ruby_value_type.
@ RUBY_T_STRING
Definition: value_type.h:120
@ RUBY_T_REGEXP
Definition: value_type.h:121