Commit 3b84af9f

3b84af9f4ffbMerged

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

Description

fix(strscan): add matched? method to stub + C impl (#814)

StringScanner#matched? was missing from the Ruby-level stub. Calls fell through to the unresolved-call warning and returned 0.

The .rb stub gets a definition that checks the @matched ivar (scan/check/scan_until/getch already update this slot, so the predicate matches CRuby's "did the last scan succeed?" semantics as long as those entry points stay consistent). The .c implementation gains a parallel sp_StringScanner_matched_p for parity, though the user-facing path is the .rb stub.

The wider gap -- the StringScanner stub doesn't actually scan yet -- is documented but out of scope for this commit.

Closes #814

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

Details

Commit
3b84af9f4ffb
Parent
a711baca34db

lib/strscan.cmodifiedView file

@@ -133,6 +133,12 @@
133133 return sc->matched ? sc->matched : "";
134134 }
135135
136+/* Issue #814: matched? -- true when the last scan succeeded. */
137+int sp_StringScanner_matched_p(sp_StringScanner *sc) {
138+ if (!sc) return 0;
139+ return sc->matched != NULL ? 1 : 0;
140+}
141+
136142 /* pos — current position */
137143 int64_t sp_StringScanner_pos(sp_StringScanner *sc) {
138144 return sc->pos;