Commit a1cb0e04
a1cb0e042740Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
String#scrub and String#index with a regex argument
scrub([repl]) replaces invalid UTF-8 bytes (default U+FFFD) via the existing sp_str_scrub. index(/re/) returns the first match offset or nil (a poly value) through sp_re_index_poly; the analyzer types the regex-arg form as poly while the string-arg form stays Integer.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- a1cb0e042740
- Parent
- fcf36ff3e435
src/analyze.cmodifiedView file
@@ -581,8 +581,13 @@
581581
!strcmp(name, "delete")) return TY_STRING;582582
if (!strcmp(name, "[]") || !strcmp(name, "slice") || !strcmp(name, "byteslice") ||583583
!strcmp(name, "force_encoding") || !strcmp(name, "b") || !strcmp(name, "encode")) return TY_STRING;584+
if (!strcmp(name, "index") && argc == 1) {585+
const char *aty = nt_type(nt, argv[0]);586+
if (aty && !strcmp(aty, "RegularExpressionNode")) return TY_POLY; /* nil on no match */587+
}584588
if (!strcmp(name, "index") || !strcmp(name, "to_i") || !strcmp(name, "count") ||585589
!strcmp(name, "oct") || !strcmp(name, "ord") || !strcmp(name, "casecmp")) return TY_INT;590+
if (!strcmp(name, "scrub")) return TY_STRING;586591
if (!strcmp(name, "casecmp?")) return TY_BOOL;587592
if (!strcmp(name, "to_f")) return TY_FLOAT;588593
if (!strcmp(name, "split") || !strcmp(name, "lines") || !strcmp(name, "scan")) return TY_STR_ARRAY;src/codegen.cmodifiedView file
Loading diff…