-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
correct nextind/prevind/thisind for SubString{String} #25531
Conversation
85e5761
to
3a0a01b
Compare
test/strings/types.jl
Outdated
@@ -188,6 +188,25 @@ let s = "lorem ipsum", sdict = Dict( | |||
end | |||
end | |||
|
|||
# proper nextind/prevind/thisind for SubString{String} | |||
let s = "∀∃∀", ss = SubString(s, 4, 4), s2 = s[4:4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this meant to be just one character for the test only? Maybe test more substrings?
a3c7eac
to
5912d26
Compare
I have to wait with this PR till #25533 is merged because of an error in implementation of |
Another bug to test this PR against:
|
5912d26
to
611eb64
Compare
The CI errors seem unrelated so this PR should be good for review and merge. |
base/strings/string.jl
Outdated
function nextind(s::String, i::Int) | ||
nextind(s::String, i::Int) = _nextind_str(s, i) | ||
|
||
function _nextind_str(s, i::Int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add ::AbstractString
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An optimal option would be to define nextind(s::Union{String, SubString{String}}, i::Int)
(the same for thisind
), but then I would have to move it to other place in the code after SubString
is defined. What do you think?
Adding ::AbstractSting
is misleading as _nextind_str
will not work for any AbstractString
and it is intended for internal use only.
So I would be obliged for a guidance what is the optimal design of code for such cases (i.e. the same body of a method applies to two different types, but at the moment of definition of the method only one of those types is defined)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it's fine as it is given that bootstrapping is difficult. Maybe just add a comment saying that s::Union{String, SubString{String}}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added - I hope this is what you meant.
Is this OK to be merged? |
695a88d
to
30ac0af
Compare
Rerunning the tests to be sure, but then yes, this is good to go. |
✔️ flush. |
An attempt to correct incorrect behavior reported in #25478.
Also fixes those two problems:
In general I want
SubString
to behave identically toString
created usinggetindex
with the same range.It seems that it is enough to remove all methods from substring.jl and extend signatures in string.jl, but I am still checking corner cases, so it is WIP still (but hopefully CI will pass).