-
-
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
Improvement of the functions for handling string indexing #23765
Comments
Makes sense to me, feel free to file separate PRs (unless somebody disagrees). However I'm less convinced about See also the radical approach at #9297 (which is unlikely to be implemented in 1.0, and maybe ever). |
I have not been aware of #9297 and have written something similar independently for testing purposes :).
|
@KristofferC We will have to live with such hacks until JuliaLang#23765 is implemented.
@KristofferC We will have to live with such hacks until JuliaLang#23765 is implemented.
Having reviewed the code base for common cases of what portions of strings are extracted the following patterns appear (along with what I propose to implement):
If this would be acceptable I can push an appropriate PR. |
Makes sense to me. |
Now I see that there is a problem with the reuse of |
Good catch, but maybe that's not an issue: the one-argument method has to return an |
OK |
I have decided to partition this issue into several PRs to make it more manageable #23805 is the first (fundamental low level) part. |
|
@StefanKarpinski Is the confusion really problematic though? I'm not sure what's our policy regarding the difference between one- and two-argument methods of the same function. In some sense, it's similar to Anyway, I'd be fine with |
Might be fine and not confusing at all. Just mentioning it as a consideration. |
I would stay with Last thing to decide is what those functions should return. I opt for:
|
I would recommend (I guess there's nothing wrong with |
@TotalVerb Agreed with new verbs. That is why I want to go with Here goes the definition of
and the tests:
|
Reading it now I think that |
Strings will need a separate implementation anyway (because of For general collections:
|
Sure, but the API can be generalized. Was not suggesting it should be done here. |
Indexing and iteration are not the same at all so that would absolutely not work for general collections. The state object (which need not be a valid index) can be passed to |
Related to discussion in #23805 about
|
Prompted by #23880 (and earlier fixes I have made) a pattern that is commonly used is If there would be a decision that handling of a pattern select characters from i to j, excluding j is important enough |
IMHO these things would be better handled via a |
#23960 implements |
Improved |
There is only one open point left in this issue - should @nalimilan I would discuss the issue of |
In #24414 I propose how the implementation of I think that we should encourage users to use only valid indices, but |
All done in this issue. Close? |
Assuming that #22572 and #22511 go through tests and get accepted I have the following proposal.
My experience from making #22572 and #22511 go though CI show that I would expect many users to make errors in indexing strings using something like
somestring[2:end-1]
. The problem is that such a construct will pass typical tests as it is valid for ASCII characters but invalid in general.Here are my thoughts how this risk could be minimized:
nextind
andprevind
functions and the use ofSubString
type;count::Int
tonextind
andprevind
that defaults to1
and indicates the number of characters to move innextind
/prevind
(such cases happen in the code);count::Int
tochop
that defaults to1
giving number of characters to remove at the end of the string;lchop(s::AbstractString, count:Int) = SubString(s, nextind(s, 1, count), endof(s))
(I am not sure about a name) that is identical tochop
but removes characters from the beginning of the string.This list would cover the most common cases I have encountered. I do not make a PR here because #22572 and #22511 have to be merged first and maybe there would be already some comments regarding the proposal.
The text was updated successfully, but these errors were encountered: