Skip to content

lastIndexOf' with index greater than string length returns Nothing #91

Closed
@hdgarrood

Description

@hdgarrood

In the JavaScript API, the fromIndex parameter in str.lastIndexOf(pattern [, fromIndex]), perhaps surprisingly, represents the index at which to stop searching (if we imagine the search proceeds from left-to-right). This means that if you provide a fromIndex which is greater than or equal to the string's length, in JS, it's equivalent to searching the whole string, i.e. not specifying that parameter at all. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf

However, in this library, the bounds check in lastIndexOf' means that e.g. lastIndexOf' (Pattern "a") 3 "aa" comes out as Nothing. I'd suggest getting rid of this check entirely, so that this matches better with the JS behaviour. This is a breaking change unfortunately.

Incidentally there are one or two other breaking changes I'd like to do (#81, #78, and also renaming Data.String.CodePoints to Data.String and renaming Data.String to Data.String.CodeUnits) so maybe we could do all of these the next time we break everything (i.e. when we release 0.12?)

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