Commit ddbb8754

ddbb87544ebeMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 6 files · +2 added · ~4 modified

Description

Implement StringScanner#[] capture-group accessor

After a scan/check/scan_until, StringScanner#[n] returns the nth capture group of the last match (group 0 is the whole match), or nil when there was no match, the index is out of range, or the group didn't participate. The scanner now stores the capture offsets from re_exec (previously it only kept the full match), and a new sp_StringScanner_aref slices the source for the requested group.

Fixes #1038

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
ddbb87544ebe
Parent
1898605dc753

lib/sp_runtime.hmodifiedView file

@@ -3882,6 +3882,7 @@
38823882 const char *sp_StringScanner_scan(sp_StringScanner *sc, mrb_regexp_pattern *pat);
38833883 const char *sp_StringScanner_check(sp_StringScanner *sc, mrb_regexp_pattern *pat);
38843884 const char *sp_StringScanner_scan_until(sp_StringScanner *sc, mrb_regexp_pattern *pat);
3885+const char *sp_StringScanner_aref(sp_StringScanner *sc, mrb_int n);
38853886 const char *sp_StringScanner_matched(sp_StringScanner *sc);
38863887 mrb_bool sp_StringScanner_matched_p(sp_StringScanner *sc);
38873888 mrb_int sp_StringScanner_pos(sp_StringScanner *sc);