summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-07-26 15:57:03 -0400
committerPeter Zhu <peter@peterzhu.ca>2023-07-27 13:33:40 -0400
commit7193b404a1a56e50f8046d0382914907020c1559 (patch)
treef0d17c30d36039eab9b8c421e24d412535e05d5e /include
parente5effa4bd063f454f9f304e6f9fbf9dd8b353a76 (diff)
Add function rb_reg_onig_match
rb_reg_onig_match performs preparation, error handling, and cleanup for matching a regex against a string. This reduces repetitive code and removes the need for StringScanner to access internal data of regex.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8123
Diffstat (limited to 'include')
-rw-r--r--include/ruby/re.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/include/ruby/re.h b/include/ruby/re.h
index 3892d6e7f2..52faeb1e98 100644
--- a/include/ruby/re.h
+++ b/include/ruby/re.h
@@ -18,6 +18,7 @@
#include <stdio.h>
+#include "ruby/onigmo.h"
#include "ruby/regex.h"
#include "ruby/internal/core/rmatch.h"
#include "ruby/internal/dllexport.h"
@@ -105,25 +106,28 @@ long rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, int dir);
VALUE rb_reg_quote(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.
+ * Runs a regular expression match using function `match`. Performs preparation,
+ * error handling, and memory cleanup.
*
* @param[in] re Target regular expression.
* @param[in] str What `re` is about to run on.
+ * @param[in] match The function to run to match `str` against `re`.
+ * @param[in] args Pointer to arguments to pass into `match`.
+ * @param[out] regs Registers on a successful match.
* @exception rb_eArgError `re` does not fit for `str`.
* @exception rb_eEncCompatError `re` and `str` are incompatible.
* @exception rb_eRegexpError `re` is malformed.
- * @return A preprocessesed pattern buffer ready to be applied to `str`.
- * @note The return value is manages by our GC. Don't free.
+ * @return Match position on a successful match, `ONIG_MISMATCH` otherwise.
*
* @internal
*
- * The return type, `regex_t *`, is defined in `<ruby/onigmo.h>`, _and_
+ * The type `regex_t *` is defined in `<ruby/onigmo.h>`, _and_
* _conflicts_ with POSIX's `<regex.h>`. We can no longer save the situation
* at this point. Just don't mix the two.
*/
-regex_t *rb_reg_prepare_re(VALUE re, VALUE str);
+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);
/**
* Duplicates a match data. This is roughly the same as `onig_region_copy()`,