diff options
| author | bors <bors@rust-lang.org> | 2014-10-02 03:07:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-02 03:07:17 +0000 |
| commit | 07b2c1be9dad53272575844efedfb7314fc4fb84 (patch) | |
| tree | d26dab000c4444cf6e972bb30da0392e675ca52b /src/libcollections/string.rs | |
| parent | d53874eccf0657d5d9c0a9ed9f84380d27d1c423 (diff) | |
| parent | 6e0611a48707a1f5d90aee32a02b2b15957ef25b (diff) | |
| download | rust-07b2c1be9dad53272575844efedfb7314fc4fb84.tar.gz rust-07b2c1be9dad53272575844efedfb7314fc4fb84.zip | |
auto merge of #17620 : nick29581/rust/slice4, r=aturon
cc @aturon r? anyone?
Diffstat (limited to 'src/libcollections/string.rs')
| -rw-r--r-- | src/libcollections/string.rs | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index d6adbd30264..1032a504330 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -160,7 +160,7 @@ impl String { if i > 0 { unsafe { - res.as_mut_vec().push_all(v.slice_to(i)) + res.as_mut_vec().push_all(v[..i]) }; } @@ -177,7 +177,7 @@ impl String { macro_rules! error(() => ({ unsafe { if subseqidx != i_ { - res.as_mut_vec().push_all(v.slice(subseqidx, i_)); + res.as_mut_vec().push_all(v[subseqidx..i_]); } subseqidx = i; res.as_mut_vec().push_all(REPLACEMENT); @@ -246,7 +246,7 @@ impl String { } if subseqidx < total { unsafe { - res.as_mut_vec().push_all(v.slice(subseqidx, total)) + res.as_mut_vec().push_all(v[subseqidx..total]) }; } Owned(res.into_string()) @@ -927,6 +927,7 @@ impl<S: Str> Add<S, String> for String { } } +#[cfg(stage0)] impl ops::Slice<uint, str> for String { #[inline] fn as_slice_<'a>(&'a self) -> &'a str { @@ -949,6 +950,34 @@ impl ops::Slice<uint, str> for String { } } +#[cfg(not(stage0))] +#[inline] +fn str_to_slice<'a, U: Str>(this: &'a U) -> &'a str { + this.as_slice() +} +#[cfg(not(stage0))] +impl ops::Slice<uint, str> for String { + #[inline] + fn as_slice<'a>(&'a self) -> &'a str { + str_to_slice(self) + } + + #[inline] + fn slice_from<'a>(&'a self, from: &uint) -> &'a str { + self[][*from..] + } + + #[inline] + fn slice_to<'a>(&'a self, to: &uint) -> &'a str { + self[][..*to] + } + + #[inline] + fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str { + self[][*from..*to] + } +} + /// Unsafe operations #[unstable = "waiting on raw module conventions"] pub mod raw { |
