Skip to content

find and rfind differ on empty needle #18128

@n5m

Description

@n5m

find and rfind return different values when the string that is being searched for has length 0.

Example

import strutils

doAssert "abc".find("") == 0
doAssert "abc".rfind("") == -1

Current Output

Both assertions pass.

Expected Output

One of the following:

  1. find and rfind both return 0
  2. find and rfind both return -1
  3. find returns low("abc"), and rfind returns high("abc")

Which one is the best?

Additional Information

git hash cfe1924

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-05-29
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: cfe19247e856950f7facaf7adbc50bca8dec3990
active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions