-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add String::split_off. #38056
Add String::split_off. #38056
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
cc @rust-lang/libs |
LGTM. |
Looks good to me too. Can you add some tests as well? Also, should the index check be |
@alexcrichton Yes and yes. Tests added. Not sure where I should add them, although where they are now should work. |
#[unstable(feature = "string_split_off", issue = "0")] | ||
pub fn split_off(&mut self, mid: usize) -> String { | ||
assert!(self.is_char_boundary(mid)); | ||
assert!(mid <= self.len()); |
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.
The self.is_char_boundary
already returns false
for mid > self.len()
, so this assertion is dead.
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.
You also probably want to use slice_error_fail
rather than plain assertion, because it will result in less code in callers and perhaps a bit better message (even if you specify mid
for both start
and end
arguments of that function).
never mind, the slice_error_fail is private to core::str
.
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 It appears that a few other functions in string.rs
do both checks; how about I leave the redundant check in this commit and remove the redundant calls in another pull request?
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.
Works for me.
You ought to rebase your branch onto the master rather than merge it in like this. |
The tests you added should be moved into this file: https://github.com/rust-lang/rust/blob/master/src/libcollectionstest/str.rs |
Looks great to me, thanks! Could you also open a new issue to track this method? If you cc me I'll tag it appropriately and then we can fill it in for the tracking issue here. It looks like the travis build has a few errors as well? |
Issue made, fixed the broken test that was causing the build to fail. |
/// let mut hello = String::from("Hello, World!"); | ||
/// let world = hello.split_off(7); | ||
/// assert_eq!(s, "Hello, "); | ||
/// assert_eq!(s2, "World!"); |
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.
s
and s2
are called hello
and world
.
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.
This is what I get for copy-pasting on a pull request. >.<
The doc tests may still need an update?
Also, could you squash the commits down into one? |
Rebased, squashed, and the doc test should be passing now. |
@bors: r+ Thanks! |
📌 Commit cbf734f has been approved by |
⌛ Testing commit cbf734f with merge e00b9d0... |
💔 Test failed - auto-mac-64-opt |
@bors: retry
…On Fri, Dec 2, 2016 at 1:10 PM, bors ***@***.***> wrote:
💔 Test failed - auto-mac-64-opt
<https://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/11194>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38056 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95KVAX1bugjeDEQfvN5GHmNaeA9exks5rEIlEgaJpZM4K-I6O>
.
|
Add String::split_off. This seems to match up with the latest version of the collection reform, and seems useful enough to add. First pull request!
⌛ Testing commit cbf734f with merge 24175e8... |
Remove redundant assertion near is_char_boundary Follow-up from #38056. `is_char_boundary` already checks for `idx <= len`, so, an extra assertion is redundant.
This seems to match up with the latest version of the collection reform, and seems useful enough to add. First pull request!