fix #18128 rfind on empty needle returns rightmost index (#20430)

rfind on empty needle returns haystack len
This commit is contained in:
n5m
2022-09-26 19:39:22 +00:00
committed by GitHub
parent b213913dcb
commit 9ca88a1889
2 changed files with 18 additions and 13 deletions

View File

@@ -2022,7 +2022,8 @@ func rfind*(s, sub: string, start: Natural = 0, last = -1): int {.rtl,
## See also:
## * `find func<#find,string,string,Natural,int>`_
if sub.len == 0:
return -1
let rightIndex: Natural = if last < 0: s.len else: last
return max(start, rightIndex)
if sub.len > s.len - start:
return -1
let last = if last == -1: s.high else: last