-
Notifications
You must be signed in to change notification settings - Fork 73
lastIndexOf' with index greater than string length returns Nothing #91
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
Comments
Previous discussion: #55. |
Can we do this as part of the updates for 0.14? |
This is one of those sneaky hidden breaking changes that isn't communicated in the types, it's a shame there's not a good way of knowing how much code this is likely to affect 😕 |
I think this is such a weird behaviour that someone almost certainly would have opened an issue by now if they had actually run into it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the JavaScript API, the
fromIndex
parameter instr.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 afromIndex
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/lastIndexOfHowever, in this library, the bounds check in
lastIndexOf'
means that e.g.lastIndexOf' (Pattern "a") 3 "aa"
comes out asNothing
. 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
toData.String
and renamingData.String
toData.String.CodeUnits
) so maybe we could do all of these the next time we break everything (i.e. when we release 0.12?)The text was updated successfully, but these errors were encountered: