Commit d05a7a87

d05a7a878e28Merged

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

Description

String split variants and each_char/each_line/each_byte

split (no arg / " ") uses whitespace mode (sp_str_split_ws); split(sep, limit) uses sp_str_split_limit. each_char/each_line/each_byte iterate (char/line=string, byte=int) and return self, working in both statement and expression position.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
d05a7a878e28
Parent
6a66b35800e7

src/analyze.cmodifiedView file

@@ -406,6 +406,7 @@
406406 if (!strcmp(name, "casecmp?")) return TY_BOOL;
407407 if (!strcmp(name, "to_f")) return TY_FLOAT;
408408 if (!strcmp(name, "split") || !strcmp(name, "lines")) return TY_STR_ARRAY;
409+ if (!strcmp(name, "each_char") || !strcmp(name, "each_line") || !strcmp(name, "each_byte")) return TY_STRING;
409410 if (!strcmp(name, "bytes")) return TY_INT_ARRAY;
410411 if (!strcmp(name, "gsub") || !strcmp(name, "sub") || !strcmp(name, "tr") ||
411412 !strcmp(name, "center") || !strcmp(name, "ljust") || !strcmp(name, "rjust"))
@@ -1461,6 +1462,10 @@
14611462 if ((!strcmp(name, "times") || !strcmp(name, "upto") ||
14621463 !strcmp(name, "downto") || !strcmp(name, "step")) && rt == TY_INT)
14631464 pt = TY_INT;
1465+ else if (rt == TY_STRING && (!strcmp(name, "each_char") || !strcmp(name, "each_line")))
1466+ pt = TY_STRING;
1467+ else if (rt == TY_STRING && !strcmp(name, "each_byte"))
1468+ pt = TY_INT;
14641469 else if ((!strcmp(name, "each") || !strcmp(name, "map") || !strcmp(name, "collect") ||
14651470 !strcmp(name, "select") || !strcmp(name, "reject") || !strcmp(name, "filter") ||
14661471 !strcmp(name, "find") || !strcmp(name, "detect") || !strcmp(name, "each_with_index") ||