-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement std::str::replacen #36347
Implement std::str::replacen #36347
Conversation
It's rare that @rust-highfive didn't show up 😮 |
/// let s = "this is old"; | ||
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10)); | ||
/// ``` | ||
#[stable(feature = "str_replacen", since = "1.13.0")] |
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.
Insta-stable? AFAICT there’s no tracking issue which went through FCP for stabilisation?
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.
@nagisa I'm sorry... Should I submit a RFC about this? BTW, where can I know the process of accepting a new method?
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 unstable method with a corresponding tracking issue may be enough.
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.
@nagisa Am I supposed to open the tracking issue by myself?
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 suggest to only do that after you get thumbs-up from the libs team for the feature you’re adding. In the mean-time you can use 0
as a placeholder issue for the attribute.
This PR needs a reviewer, @rust-lang/libs. |
e89edb9
to
f89f3a0
Compare
@nagisa Thanks for your advice! 😄 |
Seems quite niche to me. |
f89f3a0
to
1b65a57
Compare
let mut result = String::with_capacity(32); | ||
let matched = self.match_indices(pat); | ||
let mut last_end = 0; | ||
for (_, (start, part)) in (0..count).zip(matched) { |
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.
Using .take(count) would be the more typical way to limit the number of iterations here. (I'd understand it right away :D)
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.
Good point!
1b65a57
to
2b95aab
Compare
Discussed at libs triage today the decision was to merge. @knight42 could you open an issue on rust-lang/rust to track the stabilization of this and update the |
2b95aab
to
ebda770
Compare
@alexcrichton Great to hear that! 🎉 The |
@bors: r+ Thanks! |
📌 Commit ebda770 has been approved by |
⌛ Testing commit ebda770 with merge e25e32c... |
💔 Test failed - auto-win-msvc-64-opt-rustbuild |
@alexcrichton the failure seems spurious |
@bors: retry On Tue, Sep 13, 2016 at 8:59 PM, Jian Zeng notifications@github.com wrote:
|
Implement std::str::replacen Replaces first N matches of a pattern with another string. ``` assert_eq!("acaaa".replacen(a, "b", 3), "bcbba") ```
Replaces first N matches of a pattern with another string.