Skip to content

Add reverse substring search - #841

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
KingEmma7:fix/reverse-substring-search
Oct 2, 2026
Merged

LunaStev merged 1 commit into
wavefnd:masterfrom
KingEmma7:fix/reverse-substring-search

Conversation

@KingEmma7

@KingEmma7 KingEmma7 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add std::string::find::rfind(s: str, needle: str) -> i32 to return the last matching byte offset or -1. For example, rfind("ababa", "aba") returns 2. An empty needle matches the end of the string.

Motivation

Closes #716. Callers can locate the last multi-byte delimiter with a standard-library helper.

Target and compatibility impact

The helper scans candidate offsets backward after checking the string lengths and stops before decrementing zero. It compares bytes, allocates nothing and leaves both inputs untouched. Existing find, count and rfind_char behavior remains unchanged. Includes API contract comments and a string example. Standard-library changes retain Apache-2.0, and the example/test changes retain MPL-2.0.

Validation

Revalidated after rebasing onto master at 555ebf2d5de8bb1eb48a87b6bb3740cf01085282.

  • Real Wave runtime regressions at O0/O2 cover missing and oversized needles, empty strings, overlaps, UTF-8 byte offsets, NUL termination, unchanged input storage and preserved search helpers.
  • The original module rejects the missing symbol. Four incorrect implementations fail at O0/O2: first-match search, empty needles matching zero, oversized needles matching, and character offsets replacing byte offsets.
  • Formatting, standard-library policy, Python syntax/tooling tests (172 run, one skipped), warning-free rustdoc, Clippy with warnings denied, locked release build and locked workspace/all-target Rust tests (359 passed with --test-threads=1).
  • After an intermittent linker failure involving shared target/main.o, the isolated compiler test and the full serialized Rust suite passed.
  • Corpus check: 292 passed. All 26 standard-library examples ran successfully on macOS arm64 with Rust 1.89.0 and LLVM/LLD 21.1.8. Cross-platform CI results are available in this PR's checks.

Checklist

  • Commits include a DCO Signed-off-by line.
  • Tests cover new behavior or the PR explains why no test is needed.
  • User-facing changes include documentation or diagnostics updates.
  • The change preserves the license boundary between the compiler and std/.

@LunaStev

LunaStev commented Oct 2, 2026

Copy link
Copy Markdown
Member

Could you please rebase this PR onto the latest master and resolve the current conflicts? The implementation itself looks good; it just needs to be brought up to date with the recent changes. Thanks!

@KingEmma7
KingEmma7 force-pushed the fix/reverse-substring-search branch from 6ea2610 to 59b2af6 Compare October 2, 2026 13:46
Signed-off-by: Emmanuel Mawulolo Tagbor <[email protected]>
@LunaStev

LunaStev commented Oct 2, 2026

Copy link
Copy Markdown
Member

#840 has now been merged into master, which introduced another conflict with this PR. Could you please rebase onto the latest master once more and resolve the new conflicts? Thanks!

@KingEmma7
KingEmma7 force-pushed the fix/reverse-substring-search branch from 59b2af6 to 632983f Compare October 2, 2026 14:14
@LunaStev
LunaStev merged commit e5c17ef into wavefnd:master Oct 2, 2026
25 of 26 checks passed
@LunaStev LunaStev mentioned this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add reverse substring search to std::string::find

2 participants