diff options
| author | tormol <t.b.moltu@lyse.net> | 2016-09-08 13:54:39 +0200 |
|---|---|---|
| committer | tormol <t.b.moltu@lyse.net> | 2016-09-28 09:03:30 +0200 |
| commit | 13a2dd96fe824cc5d61e94ed380db0114efdd014 (patch) | |
| tree | 808a2f28e42625a2e5bc4a88abf2d46c34727b32 /src/libcollections/string.rs | |
| parent | a059cb2f3344c0a9efae17dde3d0e16a55ce93db (diff) | |
| download | rust-13a2dd96fe824cc5d61e94ed380db0114efdd014.tar.gz rust-13a2dd96fe824cc5d61e94ed380db0114efdd014.zip | |
[breaking-change] std: change `encode_utf{8,16}()` to take a buffer and return a slice
They panic if the buffer is too small.
Diffstat (limited to 'src/libcollections/string.rs')
| -rw-r--r-- | src/libcollections/string.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index cff0308d4af..e4930ae3572 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -975,7 +975,7 @@ impl String { pub fn push(&mut self, ch: char) { match ch.len_utf8() { 1 => self.vec.push(ch as u8), - _ => self.vec.extend_from_slice(ch.encode_utf8().as_slice()), + _ => self.vec.extend_from_slice(ch.encode_utf8(&mut [0;4]).as_bytes()), } } @@ -1131,10 +1131,11 @@ impl String { let len = self.len(); assert!(idx <= len); assert!(self.is_char_boundary(idx)); - let bits = ch.encode_utf8(); + let mut bits = [0; 4]; + let bits = ch.encode_utf8(&mut bits).as_bytes(); unsafe { - self.insert_bytes(idx, bits.as_slice()); + self.insert_bytes(idx, bits); } } |
