use str::not_utf8::cond;
if !is_utf8(vv) {
- let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).get();
+ let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap();
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
first_bad_byte as uint))
} else {
use str::not_utf8::cond;
if !is_utf8(vv) {
- let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).get();
+ let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).unwrap();
cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
first_bad_byte as uint))
} else {
/// If begin is greater than end.
/// If end is greater than the length of the string.
#[inline]
- pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str {
+ pub unsafe fn slice_bytes<'a>(s: &'a str, begin: uint, end: uint) -> &'a str {
do s.as_imm_buf |sbuf, n| {
assert!((begin <= end));
assert!((end <= n));
let new_len = s.len() + 1;
s.reserve_at_least(new_len);
do s.as_mut_buf |buf, len| {
- *ptr::mut_offset(buf, len as int) = b;
+ *ptr::mut_offset(buf, (len-1) as int) = b;
}
set_len(&mut *s, new_len);
}
assert!(!" _ ".is_whitespace());
}
+ #[test]
+ fn test_push_byte() {
+ let mut s = ~"ABC";
+ unsafe{raw::push_byte(&mut s, 'D' as u8)};
+ assert_eq!(s, ~"ABCD");
+ }
+
#[test]
fn test_shift_byte() {
let mut s = ~"ABC";