Commit c583b523
c583b523efaaMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
String#count with multiple charset args
count(a, b, ...) counts characters in the intersection of the charsets (each spec may negate with a leading ^). Lowers to the existing sp_str_count_n runtime helper with a C array of the argument strings; the single-arg form is unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- c583b523efaa
- Parent
- 78e2d12da4c2
src/codegen.cmodifiedView file
@@ -2103,6 +2103,11 @@
21032103
}21042104
else if (!strcmp(name, "delete") && argc == 1) { buf_printf(b, "sp_str_delete(%s, ", r); emit_expr(c, argv[0], b); buf_puts(b, ")"); }21052105
else if (!strcmp(name, "count") && argc == 1) { buf_printf(b, "sp_str_count(%s, ", r); emit_expr(c, argv[0], b); buf_puts(b, ")"); }2106+
else if (!strcmp(name, "count") && argc >= 2) {2107+
buf_printf(b, "sp_str_count_n(%s, (const char *[]){", r);2108+
for (int a = 0; a < argc; a++) { if (a) buf_puts(b, ", "); emit_expr(c, argv[a], b); }2109+
buf_printf(b, "}, %d)", argc);2110+
}21062111
else if (!strcmp(name, "lines") && argc == 0) buf_printf(b, "sp_str_lines(%s)", r);21072112
else if (!strcmp(name, "bytes") && argc == 0) buf_printf(b, "sp_str_bytes(%s)", r);21082113
else if (!strcmp(name, "to_i") && argc == 0) buf_printf(b, "sp_str_to_i_strict(%s)", r);