Debian Codegraph @

include/ruby/internal/intern/re.h

raw
1 #ifndef RBIMPL_INTERN_RE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_INTERN_RE_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Public APIs related to ::rb_cRegexp.
22 */
23 #include "ruby/internal/attr/nonnull.h"
24 #include "ruby/internal/dllexport.h"
25 #include "ruby/internal/value.h"
26
27 RBIMPL_SYMBOL_EXPORT_BEGIN()
28
29 /* re.c */
30
31 /**
32 * @deprecated This macro once was a thing in the old days, but makes no sense
33 * any longer today. Exists here for backwards compatibility
34 * only. You can safely forget about it.
35 *
36 * @internal
37 *
38 * This was a function that switched between memcmp and rb_memcicmp depending
39 * on then-called `ruby_ignorecase`, or the `$=` global variable. That feature
40 * was abandoned in sometime around version 1.9.0.
41 */
42 #define rb_memcmp memcmp
43
44 /**
45 * Identical to st_locale_insensitive_strcasecmp(), except it is timing safe
46 * and returns something different.
47 *
48 * @param[in] s1 Comparison LHS.
49 * @param[in] s2 Comparison RHS.
50 * @param[in] n Comparison shall stop after first `n` bytes are scanned.
51 * @retval <0 `s1` is "less" than `s2`.
52 * @retval 0 Both sides converted into lowercase would be identical.
53 * @retval >0 `s1` is "greater" than `s2`.
54 * @note The "case" here means that of the POSIX Locale.
55 *
56 * @internal
57 *
58 * Can accept NULLs as long as n is also 0, and returns 0.
59 */
60 int rb_memcicmp(const void *s1,const void *s2, long n);
61
62 /**
63 * Asserts that the given MatchData is "occupied". MatchData shares its
64 * backend storages with its Regexp object. But programs can destructively
65 * tamper its contents. Calling this function beforehand shall prevent such
66 * modifications to spill over into other objects.
67 *
68 * @param[out] md Target instance of ::rb_cMatch.
69 * @post The object is "busy".
70 *
71 * @internal
72 *
73 * There is rb_match_unbusy internally, but extension libraries are left unable
74 * to do so.
75 */
76 void rb_match_busy(VALUE md);
77
78 /**
79 * Identical to rb_reg_nth_match(), except it just returns Boolean. This could
80 * skip allocating a returning string, resulting in reduced memory footprints
81 * if applicable.
82 *
83 * @param[in] n Match index.
84 * @param[in] md An instance of ::rb_cMatch.
85 * @exception rb_eTypeError `md` is not initialised.
86 * @retval RUBY_Qnil There is no `n`-th capture.
87 * @retval RUBY_Qfalse There is a `n`-th capture and is empty.
88 * @retval RUBY_Qtrue There is a `n`-th capture that has something.
89 *
90 */
91 VALUE rb_reg_nth_defined(int n, VALUE md);
92
93 /**
94 * Queries the nth captured substring.
95 *
96 * @param[in] n Match index.
97 * @param[in] md An instance of ::rb_cMatch.
98 * @exception rb_eTypeError `md` is not initialised.
99 * @retval RUBY_Qnil There is no `n`-th capture.
100 * @retval otherwise An allocated instance of ::rb_cString containing
101 * the contents captured.
102 */
103 VALUE rb_reg_nth_match(int n, VALUE md);
104
105 /**
106 * Queries the index of the given named capture. Captures could be named. But
107 * that doesn't mean named ones are not indexed. A regular expression can mix
108 * named and non-named captures, and they are all indexed. This function
109 * converts from a name to its index.
110 *
111 * @param[in] match An instance of ::rb_cMatch.
112 * @param[in] backref Capture name, in String, Symbol, or Numeric.
113 * @exception rb_eIndexError No such named capture.
114 * @return The index of the given name.
115 */
116 int rb_reg_backref_number(VALUE match, VALUE backref);
117
118 /**
119 * This just returns the argument, stringified. What a poor name.
120 *
121 * @param[in] md An instance of ::rb_cMatch.
122 * @return Its 0th capture (i.e. entire matched string).
123 */
124 VALUE rb_reg_last_match(VALUE md);
125
126 /**
127 * The portion of the original string before the given match.
128 *
129 * @param[in] md An instance of ::rb_cMatch.
130 * @return Its "prematch". This is perl's ``$```.
131 */
132 VALUE rb_reg_match_pre(VALUE md);
133
134 /**
135 * The portion of the original string after the given match.
136 *
137 * @param[in] md An instance of ::rb_cMatch.
138 * @return Its "postmatch". This is perl's `$'`.
139 */
140 VALUE rb_reg_match_post(VALUE md);
141
142 /**
143 * The portion of the original string that captured at the very last.
144 *
145 * @param[in] md An instance of ::rb_cMatch.
146 * @return Its "lastmatch". This is perl's `$+`.
147 */
148 VALUE rb_reg_match_last(VALUE md);
149
150 /**
151 * @private
152 *
153 * @deprecated This macro once was a thing in the old days, but makes no sense
154 * any longer today. Exists here for backwards compatibility
155 * only. You can safely forget about it.
156 */
157 #define HAVE_RB_REG_NEW_STR 1
158
159 /**
160 * Identical to rb_reg_new(), except it takes the expression in Ruby's string
161 * instead of C's.
162 *
163 * @param[in] src Source code in String.
164 * @param[in] opts Options e.g. ONIG_OPTION_MULTILINE.
165 * @exception rb_eRegexpError `src` and `opts` do not interface.
166 * @return Allocated new instance of ::rb_cRegexp.
167 */
168 VALUE rb_reg_new_str(VALUE src, int opts);
169
170 RBIMPL_ATTR_NONNULL(())
171 /**
172 * Creates a new Regular expression.
173 *
174 * @param[in] src Source code.
175 * @param[in] len `strlen(src)`.
176 * @param[in] opts Options e.g. ONIG_OPTION_MULTILINE.
177 * @return Allocated new instance of ::rb_cRegexp.
178 */
179 VALUE rb_reg_new(const char *src, long len, int opts);
180
181 /**
182 * Allocates an instance of ::rb_cRegexp.
183 *
184 * @private
185 *
186 * Nobody should call this function. Regular expressions that are not
187 * initialised must not exist in the wild.
188 */
189 VALUE rb_reg_alloc(void);
190
191 /**
192 * Initialises an instance of ::rb_cRegexp.
193 *
194 * @private
195 *
196 * This just raises for ordinal regexp objects. Extension libraries must not
197 * use.
198 */
199 VALUE rb_reg_init_str(VALUE re, VALUE s, int options);
200
201 /**
202 * This is the match operator.
203 *
204 * @param[in] re An instance of ::rb_cRegexp.
205 * @param[in] str An instance of ::rb_cString.
206 * @exception rb_eTypeError `str` is not a string.
207 * @exception rb_eRegexpError Error inside of Onigmo (unlikely).
208 * @retval RUBY_Qnil Match failed.
209 * @retval otherwise Matched position (character index inside of
210 * `str`).
211 * @post `Regexp.last_match` is updated.
212 * @post `$&`, `$~`, etc., are updated.
213 * @note If you do this in ruby, named captures are assigned to local
214 * variable of the local scope. But that doesn't happen here. The
215 * assignment is done by the interpreter.
216 */
217 VALUE rb_reg_match(VALUE re, VALUE str);
218
219 /**
220 * Identical to rb_reg_match(), except it matches against rb_lastline_get()
221 * (or, the `$_`).
222 *
223 * @param[in] re An instance of ::rb_cRegexp.
224 * @exception rb_eRegexpError Error inside of Onigmo (unlikely).
225 * @retval RUBY_Qnil Match failed or `$_` is absent.
226 * @retval otherwise Matched position (character index inside of
227 * `$_`).
228 * @post `Regexp.last_match` is updated.
229 * @post `$&`, `$~`, etc., are updated.
230 */
231 VALUE rb_reg_match2(VALUE re);
232
233 /**
234 * Queries the options of the passed regular expression.
235 *
236 * @param[in] re An instance of ::rb_cRegexp.
237 * @return Its options.
238 * @note Possible return values are defined in Onigmo.h.
239 */
240 int rb_reg_options(VALUE re);
241
242 RBIMPL_SYMBOL_EXPORT_END()
243
244 #endif /* RBIMPL_INTERN_RE_H */