-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Errors for invalid range indexing into strings? #5446
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
I would rather consider this as a bug. |
Looking at the source, this seems deliberate. function getindex(s::UTF8String, r::Range1{Int})
a, b = first(r), last(r)
i = isvalid(s,a) ? a : nextind(s,a)
j = b < endof(s) ? nextind(s,b)-1 : endof(s.data)
UTF8String(s.data[i:j])
end It might be useful in some settings to ensure that any index range returns something, but it seems like this code is written to obfuscate the details of variable length encodings, more than to help users to deal with it. The |
I'm not sure we should allow every index range to return something. That's not how arrays work, for example:
|
How could I not mention that I found out that that is not how |
This still seems funky julia> a = "æøå";
julia> a[1:1] * a[2:2] * a[3:3] * a[4:4] * a[5:5]
"æøå"
julia> a[1:1] * a[2:2] * a[3:3] * a[4:4] * a[5:5] * a[6:6]
ERROR: BoundsError()
julia> length(a.data)
6 |
Accessing |
Accessing Now that we are in the business of changing the behaviour. Is there any reason to not throw the not yet defined |
Giving that error is fine with me. I was just being cautious. Again, in |
+1 for throwing an error |
This feels weird:
Could we throw the BoundsError if the second index goes past |
I might not appreciate the reasoning behind it, but I find the following behaviors for range indexing into strings a little odd:
The text was updated successfully, but these errors were encountered: