@@ -1164,6 +1164,7 @@ pub mod traits {
1164
1164
fn equiv ( & self , other : & S ) -> bool { eq_slice ( * self , other. as_slice ( ) ) }
1165
1165
}
1166
1166
1167
+ #[ cfg( stage0) ]
1167
1168
impl ops:: Slice < uint , str > for str {
1168
1169
#[ inline]
1169
1170
fn as_slice_ < ' a > ( & ' a self ) -> & ' a str {
@@ -1172,17 +1173,39 @@ pub mod traits {
1172
1173
1173
1174
#[ inline]
1174
1175
fn slice_from_ < ' a > ( & ' a self , from : & uint ) -> & ' a str {
1175
- self . slice_from ( * from)
1176
+ super :: slice_from_impl ( & self , * from)
1176
1177
}
1177
1178
1178
1179
#[ inline]
1179
1180
fn slice_to_ < ' a > ( & ' a self , to : & uint ) -> & ' a str {
1180
- self . slice_to ( * to)
1181
+ super :: slice_to_impl ( & self , * to)
1181
1182
}
1182
1183
1183
1184
#[ inline]
1184
1185
fn slice_ < ' a > ( & ' a self , from : & uint , to : & uint ) -> & ' a str {
1185
- self . slice ( * from, * to)
1186
+ super :: slice_impl ( & self , * from, * to)
1187
+ }
1188
+ }
1189
+ #[ cfg( not( stage0) ) ]
1190
+ impl ops:: Slice < uint , str > for str {
1191
+ #[ inline]
1192
+ fn as_slice < ' a > ( & ' a self ) -> & ' a str {
1193
+ self
1194
+ }
1195
+
1196
+ #[ inline]
1197
+ fn slice_from < ' a > ( & ' a self , from : & uint ) -> & ' a str {
1198
+ super :: slice_from_impl ( & self , * from)
1199
+ }
1200
+
1201
+ #[ inline]
1202
+ fn slice_to < ' a > ( & ' a self , to : & uint ) -> & ' a str {
1203
+ super :: slice_to_impl ( & self , * to)
1204
+ }
1205
+
1206
+ #[ inline]
1207
+ fn slice < ' a > ( & ' a self , from : & uint , to : & uint ) -> & ' a str {
1208
+ super :: slice_impl ( & self , * from, * to)
1186
1209
}
1187
1210
}
1188
1211
}
@@ -1835,6 +1858,38 @@ fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! {
1835
1858
begin, end, s) ;
1836
1859
}
1837
1860
1861
+ #[ inline]
1862
+ fn slice_impl < ' a > ( this : & & ' a str , begin : uint , end : uint ) -> & ' a str {
1863
+ // is_char_boundary checks that the index is in [0, .len()]
1864
+ if begin <= end &&
1865
+ this. is_char_boundary ( begin) &&
1866
+ this. is_char_boundary ( end) {
1867
+ unsafe { raw:: slice_unchecked ( * this, begin, end) }
1868
+ } else {
1869
+ slice_error_fail ( * this, begin, end)
1870
+ }
1871
+ }
1872
+
1873
+ #[ inline]
1874
+ fn slice_from_impl < ' a > ( this : & & ' a str , begin : uint ) -> & ' a str {
1875
+ // is_char_boundary checks that the index is in [0, .len()]
1876
+ if this. is_char_boundary ( begin) {
1877
+ unsafe { raw:: slice_unchecked ( * this, begin, this. len ( ) ) }
1878
+ } else {
1879
+ slice_error_fail ( * this, begin, this. len ( ) )
1880
+ }
1881
+ }
1882
+
1883
+ #[ inline]
1884
+ fn slice_to_impl < ' a > ( this : & & ' a str , end : uint ) -> & ' a str {
1885
+ // is_char_boundary checks that the index is in [0, .len()]
1886
+ if this. is_char_boundary ( end) {
1887
+ unsafe { raw:: slice_unchecked ( * this, 0 , end) }
1888
+ } else {
1889
+ slice_error_fail ( * this, 0 , end)
1890
+ }
1891
+ }
1892
+
1838
1893
impl < ' a > StrSlice < ' a > for & ' a str {
1839
1894
#[ inline]
1840
1895
fn contains < ' a > ( & self , needle : & ' a str ) -> bool {
@@ -1938,34 +1993,17 @@ impl<'a> StrSlice<'a> for &'a str {
1938
1993
1939
1994
#[ inline]
1940
1995
fn slice ( & self , begin : uint , end : uint ) -> & ' a str {
1941
- // is_char_boundary checks that the index is in [0, .len()]
1942
- if begin <= end &&
1943
- self . is_char_boundary ( begin) &&
1944
- self . is_char_boundary ( end) {
1945
- unsafe { raw:: slice_unchecked ( * self , begin, end) }
1946
- } else {
1947
- slice_error_fail ( * self , begin, end)
1948
- }
1996
+ slice_impl ( self , begin, end)
1949
1997
}
1950
1998
1951
1999
#[ inline]
1952
2000
fn slice_from ( & self , begin : uint ) -> & ' a str {
1953
- // is_char_boundary checks that the index is in [0, .len()]
1954
- if self . is_char_boundary ( begin) {
1955
- unsafe { raw:: slice_unchecked ( * self , begin, self . len ( ) ) }
1956
- } else {
1957
- slice_error_fail ( * self , begin, self . len ( ) )
1958
- }
2001
+ slice_from_impl ( self , begin)
1959
2002
}
1960
2003
1961
2004
#[ inline]
1962
2005
fn slice_to ( & self , end : uint ) -> & ' a str {
1963
- // is_char_boundary checks that the index is in [0, .len()]
1964
- if self . is_char_boundary ( end) {
1965
- unsafe { raw:: slice_unchecked ( * self , 0 , end) }
1966
- } else {
1967
- slice_error_fail ( * self , 0 , end)
1968
- }
2006
+ slice_to_impl ( self , end)
1969
2007
}
1970
2008
1971
2009
fn slice_chars ( & self , begin : uint , end : uint ) -> & ' a str {
0 commit comments