-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Introduce String::remove_matches
to remove all matches of a pattern in a string.
#50015
Conversation
r? @aidanhs (rust_highfive has picked a reviewer for you, use r? to override) |
let s = self.clone(); | ||
// FIXME: this is inefficient because we'll search from the beginning of the string in | ||
// . each iteration of the loop | ||
let mut searcher = pat.into_searcher(&s); |
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.
note that this doesn't compile, because into_searcher
immutably borrows the string, and i can't call self.vec.set_len
below if it's borrowed. not sure how to proceed
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.
Also into_searcher
consumes itself, so there's no way to call it again on a new string slice
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
String::remove_matches
to remove all matches of patterns in a string.String::remove_matches
to remove all matches of a pattern in a string.
@frewsxcv: How do you want to proceed with this PR? You mention that it currently doesn't compile, is that a problem with the pattern API or something in this PR that can be fixed? |
convertinig this to a github issue #50206 |
…joshtriplett Implement String::remove_matches Closes rust-lang#50206. I lifted the function help from `@frewsxcv's` original PR (rust-lang#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
…joshtriplett Implement String::remove_matches Closes rust-lang#50206. I lifted the function help from ``@frewsxcv's`` original PR (rust-lang#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
…joshtriplett Implement String::remove_matches Closes rust-lang#50206. I lifted the function help from `@frewsxcv's` original PR (rust-lang#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
…shtriplett Implement String::remove_matches Closes rust-lang#50206. I lifted the function help from `@frewsxcv's` original PR (rust-lang#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
Like
replace(..., "")
, but doesn't result in any allocations.