@@ -1094,18 +1094,6 @@ pub fn subslice_offset(outer: &str, inner: &str) -> uint {
1094
1094
}
1095
1095
}
1096
1096
1097
-
1098
- /**
1099
- * Returns the number of single-byte characters the string can hold without
1100
- * reallocating
1101
- */
1102
- pub fn capacity ( s : & const ~str ) -> uint {
1103
- let buf: & const ~[ u8 ] = unsafe { cast:: transmute ( s) } ;
1104
- let vcap = vec:: capacity ( buf) ;
1105
- assert ! ( vcap > 0 u) ;
1106
- vcap - 1 u
1107
- }
1108
-
1109
1097
/// Escape each char in `s` with char::escape_default.
1110
1098
pub fn escape_default( s : & str ) -> ~str {
1111
1099
let mut out: ~str = ~"";
@@ -2020,6 +2008,7 @@ pub trait OwnedStr {
2020
2008
fn append(&self, rhs: &str) -> ~str; // FIXME #4850: this should consume self.
2021
2009
fn reserve(&mut self, n: uint);
2022
2010
fn reserve_at_least(&mut self, n: uint);
2011
+ fn capacity(&self) -> uint;
2023
2012
2024
2013
fn as_bytes_with_null_consume(self) -> ~[u8];
2025
2014
}
@@ -2212,6 +2201,17 @@ impl OwnedStr for ~str {
2212
2201
self.reserve(uint::next_power_of_two(n + 1u) - 1u)
2213
2202
}
2214
2203
2204
+ /**
2205
+ * Returns the number of single-byte characters the string can hold without
2206
+ * reallocating
2207
+ */
2208
+ fn capacity(&self) -> uint {
2209
+ let buf: &const ~[u8] = unsafe { cast::transmute(self) };
2210
+ let vcap = vec::capacity(buf);
2211
+ assert!(vcap > 0u);
2212
+ vcap - 1u
2213
+ }
2214
+
2215
2215
/// Convert to a vector of bytes. This does not allocate a new
2216
2216
/// string, and includes the null terminator.
2217
2217
#[inline]
0 commit comments