Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/zz_codegen/src/runtime/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ zz_value zz_str_rfind_in(zz_value s, zz_value sub, zz_value start, zz_value end,
size_t needle_len = sub.s->len;
size_t lo, hi;
clamp_span_c((int64_t)s.s->len, start.i, end.i, &lo, &hi);
if (needle_len == 0) return (zz_value){ZZ_INT, {.i = (int64_t)lo}};
if (needle_len == 0) return (zz_value){ZZ_INT, {.i = (int64_t)hi}};
const char *fin = src + hi;
const char *p = src + lo;
int64_t best = -1;
Expand Down
2 changes: 1 addition & 1 deletion crates/zz_stdlib/src/natives/str_mod/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn find_in(hay: &[u8], needle: &[u8], start: i64, end: i64) -> i64 {
fn rfind_in(hay: &[u8], needle: &[u8], start: i64, end: i64) -> i64 {
let (s, e) = clamp_span(hay.len() as i64, start, end);
if needle.is_empty() {
return s as i64;
return e as i64;
}
match memchr::memmem::rfind(&hay[s..e], needle) {
Some(rel) => s as i64 + rel as i64,
Expand Down
4 changes: 3 additions & 1 deletion docs/stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ import std.str
| `bytes.to_ints` | `bytes.to_ints(b: bytes) -> [int]` | Opaque byte buffer as plain ints |

Offsets are bytes (O(1) per call, O(n) streaming total; matches Rust
`str::find` semantics). `length`/slicing stay char-oriented — convert
`str::find` semantics). Empty `sub`: `find`/`rfind` return the clamped
`from`, `find_in` the clamped start, `rfind_in` the clamped end,
`count_in` returns 0; `_at` never matches empty. `length`/slicing stay char-oriented — convert
explicitly when mixing. Negative inputs clamp to 0; empty `sub` returns
the clamped position for `find`/`rfind` and never matches for `_at`.
`trim_span` strips Unicode White_Space identically on VM and AOT.
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/stdlib/str_find_test.zz
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func main() {
println("in13={str.find_in(hay, hello_pat, 1, 12)}")
println("inmiss={str.find_in(hay, hello_pat, 14, 24)}")
println("inempty={str.find_in(hay, empty_pat, 3, 9)}")
println("rinemptyin={str.rfind_in(hay, empty_pat, 3, 9)}")
println("rin0={str.rfind_in(hay, hello_pat, 0, 24)}")
println("rin13={str.rfind_in(hay, hello_pat, 0, 12)}")
println("rinmiss={str.rfind_in(hay, hello_pat, 14, 24)}")
Expand Down
Loading