Skip to content

Commit 4f28dc0

Browse files
committed
---
yaml --- r: 220535 b: refs/heads/tmp c: 7469914 h: refs/heads/master i: 220533: d9479b6 220531: f7db19a 220527: fecf5f9 v: v3
1 parent 7d2d9d7 commit 4f28dc0

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2626
refs/heads/beta: c8bab9d06a179028a0d5129aa62f09d694d9cc49
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28-
refs/heads/tmp: f9005512a9d84f469b30f0d469ccc401607ce64c
28+
refs/heads/tmp: 7469914e96a511487e8248d2f8a583befb02149f
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 1b28ffa5216c845d1cef6b0cb3e5ac7db12025d0
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828

branches/tmp/src/libcollections/str.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,12 @@ impl str {
793793
core_str::StrExt::split_at(self, mid)
794794
}
795795

796+
/// Divide one mutable string slice into two at an index.
797+
#[inline]
798+
pub fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
799+
core_str::StrExt::split_at_mut(self, mid)
800+
}
801+
796802
/// An iterator over the codepoints of `self`.
797803
///
798804
/// # Examples

branches/tmp/src/libcollectionstest/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(ascii)]
1112
#![feature(append)]
1213
#![feature(bitset)]
1314
#![feature(bitvec)]

branches/tmp/src/libcollectionstest/str.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,18 @@ fn test_split_at() {
701701
assert_eq!(b, "");
702702
}
703703

704+
#[test]
705+
fn test_split_at_mut() {
706+
use std::ascii::AsciiExt;
707+
let mut s = "Hello World".to_string();
708+
{
709+
let (a, b) = s.split_at_mut(5);
710+
a.make_ascii_uppercase();
711+
b.make_ascii_lowercase();
712+
}
713+
assert_eq!(s, "HELLO world");
714+
}
715+
704716
#[test]
705717
#[should_panic]
706718
fn test_split_at_boundscheck() {

branches/tmp/src/libcore/str/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ pub trait StrExt {
12791279
where P::Searcher: ReverseSearcher<'a>;
12801280
fn find_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize>;
12811281
fn split_at(&self, mid: usize) -> (&str, &str);
1282+
fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str);
12821283
fn slice_shift_char<'a>(&'a self) -> Option<(char, &'a str)>;
12831284
fn subslice_offset(&self, inner: &str) -> usize;
12841285
fn as_ptr(&self) -> *const u8;
@@ -1591,6 +1592,20 @@ impl StrExt for str {
15911592
}
15921593
}
15931594

1595+
fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
1596+
// is_char_boundary checks that the index is in [0, .len()]
1597+
if self.is_char_boundary(mid) {
1598+
let len = self.len();
1599+
unsafe {
1600+
let self2: &mut str = mem::transmute_copy(&self);
1601+
(self.slice_mut_unchecked(0, mid),
1602+
self2.slice_mut_unchecked(mid, len))
1603+
}
1604+
} else {
1605+
slice_error_fail(self, 0, mid)
1606+
}
1607+
}
1608+
15941609
#[inline]
15951610
fn slice_shift_char(&self) -> Option<(char, &str)> {
15961611
if self.is_empty() {

0 commit comments

Comments
 (0)