-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow specification of starting index in str::find #11986
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
The API is designed to be composable: Is that what you are describing? (I think the |
Yes. In particular let y = x.find('"').unwrap()+1; x.slice(y, y + x.slice_from(y+1).find('"').unwrap()+1) (intended to find string between first two double-quote characters) let y = x.find('"').unwrap()+1; x.slice(y, x.find('"', y).unwrap()) While it's possible to do using composition, it feels somewhat clumsy, and using an iterator probably overkill for small matches like this. |
I'm personally nervous about adding more arguments for things like this; e.g. why don't we have an argument counting how many matches should be ignored; and the ending index, and then the same for the reverse versions. This specific case may be fixed by something like adding a let mut it = x.offsets('"');
x.slice(it.next().unwrap(), it.next().unwrap() + 1) That said, this sort of stuff is not great Unicode-practice. |
I was just thinking a find_from. But, it is really awful Unicode hygiene... On Sun, Feb 2, 2014 at 7:29 AM, Huon Wilson [email protected]:
|
Triage bump. Needs an RFC as |
This is bad unicode practice, and changes to the libraries will need an RFC, so yes, closing. |
I tried to use the proposed solution, but it looks that the API changed significantly. What is the current way how to find a string starting from given index? |
fix rust-lang#11986 Aliases break resolution of qualified variants in patterns
The find family of string functions currently do not have a way of specifying the starting index. This makes it difficult to find the nth occurrence of something.
cc @cmr
The text was updated successfully, but these errors were encountered: