From 037a5b1af4b66e44d6d2130cedb576c5659bac8c Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 23 Jul 2013 12:30:34 -0700 Subject: [PATCH] str: move as_mut_buf into OwnedStr, and make it `self` --- src/libstd/str.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 42b651a8e38..95cbc5aa409 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1192,7 +1192,6 @@ fn split_options_iter(&self, sep: Sep, count: uint, allow_trailing_ fn subslice_offset(&self, inner: &str) -> uint; fn as_imm_buf(&self, f: &fn(*u8, uint) -> T) -> T; - fn as_mut_buf(&self, f: &fn(*mut u8, uint) -> T) -> T; fn as_c_str(&self, f: &fn(*libc::c_char) -> T) -> T; } @@ -1965,23 +1964,6 @@ fn as_imm_buf(&self, f: &fn(*u8, uint) -> T) -> T { } } - /** - * Work with the byte buffer and length of a slice. - * - * The given length is one byte longer than the 'official' indexable - * length of the string. This is to permit probing the byte past the - * indexable area for a null byte, as is the case in slices pointing - * to full strings, or suffixes of them. - */ - #[inline] - fn as_mut_buf(&self, f: &fn(*mut u8, uint) -> T) -> T { - unsafe { - let v: *(*mut u8, uint) = cast::transmute(self); - let (buf, len) = *v; - f(buf, len) - } - } - /** * Work with the byte buffer of a string as a null-terminated C string. * @@ -2056,6 +2038,18 @@ pub trait OwnedStr { fn reserve_at_least(&mut self, n: uint); fn capacity(&self) -> uint; fn to_bytes_with_null(self) -> ~[u8]; + + /** + * Work with the mutable byte buffer and length of a slice. + * + * The given length is one byte longer than the 'official' indexable + * length of the string. This is to permit probing the byte past the + * indexable area for a null byte, as is the case in slices pointing + * to full strings, or suffixes of them. + * + * Make sure any mutations to this buffer keep this string valid UTF8. + */ + fn as_mut_buf(&mut self, f: &fn(*mut u8, uint) -> T) -> T; } impl OwnedStr for ~str { @@ -2246,6 +2240,12 @@ fn capacity(&self) -> uint { fn to_bytes_with_null(self) -> ~[u8] { unsafe { ::cast::transmute(self) } } + + #[inline] + fn as_mut_buf(&mut self, f: &fn(*mut u8, uint) -> T) -> T { + let v: &mut ~[u8] = unsafe { cast::transmute(self) }; + v.as_mut_buf(f) + } } impl Clone for ~str { -- 2.44.0