JuliaLang/julia

`findprev`/`findlast` with empty search string

Open

#39,940 opened on 2021年3月6日

GitHub で見る
 (1 comment) (0 reactions) (0 assignees)Julia (5,773 forks)batch import
bughelp wantedsearch & findstrings

Repository metrics

Stars
 (48,709 stars)
PR merge metrics
 (平均マージ 20d 6h) (30d で 157 merged PRs)

説明

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.

コントリビューターガイド