Commit 66fc04fe

66fc04fe6b6dMerged

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

Description

String#to_i(base)

Wire "ff".to_i(16) etc. to the existing sp_str_to_i_strict_base helper (handles 2..36, sign, underscores, and 0x/0b/0o prefixes), matching how the no-arg to_i already maps to sp_str_to_i_strict. Base 0 (auto-detect) is not handled.

make test: 183 pass / 6 fail / 655 error (was 181 / 5 / 658); string_to_i_base plus one more green. The new fail (string_to_i_base_zero) was previously an ERR -- base-0 auto-detect is unsupported; no passing test regressed.

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

Details

Commit
66fc04fe6b6d
Parent
1468a90ac9ec

src/codegen.cmodifiedView file

@@ -1847,6 +1847,7 @@
18471847 else if (!strcmp(name, "lines") && argc == 0) buf_printf(b, "sp_str_lines(%s)", r);
18481848 else if (!strcmp(name, "bytes") && argc == 0) buf_printf(b, "sp_str_bytes(%s)", r);
18491849 else if (!strcmp(name, "to_i") && argc == 0) buf_printf(b, "sp_str_to_i_strict(%s)", r);
1850+ else if (!strcmp(name, "to_i") && argc == 1) { buf_printf(b, "sp_str_to_i_strict_base(%s, ", r); emit_expr(c, argv[0], b); buf_puts(b, ")"); }
18501851 else if (!strcmp(name, "to_f") && argc == 0) buf_printf(b, "atof(%s)", r);
18511852 else if (!strcmp(name, "gsub") && argc == 2) {
18521853 buf_printf(b, "sp_str_gsub(%s, ", r); emit_expr(c, argv[0], b); buf_puts(b, ", "); emit_expr(c, argv[1], b); buf_puts(b, ")");