Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findprev/findlast with empty search string #39940

Open
sostock opened this issue Mar 6, 2021 · 0 comments · May be fixed by #40120
Open

findprev/findlast with empty search string #39940

sostock opened this issue Mar 6, 2021 · 0 comments · May be fixed by #40120
Labels
bug Indicates an unexpected problem or unintended behavior help wanted Indicates that a maintainer wants help on an issue or pull request search & find The find* family of functions strings "Strings!"

Comments

@sostock
Copy link
Contributor

sostock commented Mar 6, 2021

I think the behavior of findprev and findlast with an empty search string is wrong:

For non-empty search strings, findnext(needle, haystack, i) returns a range whose start is at least i. Similarly, findprev(needle, haystack, i) returns a range whose stop is at most i. Consider the following example:

julia> findnext("aa", "aaaa", 2)
2:3

julia> findprev("aa", "aaaa", 2)
1:2

However, this is not the case for an empty needle:

julia> findnext("", "aaaa", 2)
2:1

julia> findprev("", "aaaa", 2)
2:1

I think the findprev behavior is wrong, we should have findprev("", "abc", 2) === 3:2.

The same holds for findlast: I think we should have findlast("", "aaaa") === 5:4 instead of 4:3.

@sostock sostock added the search & find The find* family of functions label Mar 6, 2021
@sostock sostock added the strings "Strings!" label Mar 12, 2021
@StefanKarpinski StefanKarpinski added bug Indicates an unexpected problem or unintended behavior help wanted Indicates that a maintainer wants help on an issue or pull request labels Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior help wanted Indicates that a maintainer wants help on an issue or pull request search & find The find* family of functions strings "Strings!"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants