std: update str.push_byte to work without str trailing nulls
This commit is contained in:
parent
8567611adf
commit
5e7b666250
1 changed files with 10 additions and 1 deletions
|
|
@ -1064,15 +1064,24 @@ pub mod raw {
|
|||
}
|
||||
|
||||
/// Appends a byte to a string. (Not UTF-8 safe).
|
||||
#[cfg(stage0)]
|
||||
pub unsafe fn push_byte(s: &mut ~str, b: u8) {
|
||||
let new_len = s.len() + 1;
|
||||
s.reserve_at_least(new_len);
|
||||
do s.as_mut_buf |buf, len| {
|
||||
*ptr::mut_offset(buf, (len-1) as int) = b;
|
||||
*ptr::mut_offset(buf, len as int) = b;
|
||||
}
|
||||
set_len(&mut *s, new_len);
|
||||
}
|
||||
|
||||
/// Appends a byte to a string. (Not UTF-8 safe).
|
||||
#[cfg(not(stage0))]
|
||||
#[inline]
|
||||
pub unsafe fn push_byte(s: &mut ~str, b: u8) {
|
||||
let v: &mut ~[u8] = cast::transmute(s);
|
||||
v.push(b);
|
||||
}
|
||||
|
||||
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
|
||||
unsafe fn push_bytes(s: &mut ~str, bytes: &[u8]) {
|
||||
let new_len = s.len() + bytes.len();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue