libcore: fix indention.
This commit is contained in:
parent
5d56da1678
commit
1dc92d44be
1 changed files with 70 additions and 70 deletions
|
@ -1859,83 +1859,83 @@ mod unsafe {
|
||||||
/// Converts a byte to a string.
|
/// Converts a byte to a string.
|
||||||
unsafe fn from_byte(u: u8) -> ~str { unsafe::from_bytes([u]) }
|
unsafe fn from_byte(u: u8) -> ~str { unsafe::from_bytes([u]) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a bytewise (not UTF-8) slice from a string.
|
* Takes a bytewise (not UTF-8) slice from a string.
|
||||||
*
|
*
|
||||||
* Returns the substring from [`begin`..`end`).
|
* Returns the substring from [`begin`..`end`).
|
||||||
*
|
*
|
||||||
* # Failure
|
* # Failure
|
||||||
*
|
*
|
||||||
* If begin is greater than end.
|
* If begin is greater than end.
|
||||||
* If end is greater than the length of the string.
|
* If end is greater than the length of the string.
|
||||||
*/
|
*/
|
||||||
unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> ~str {
|
unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> ~str {
|
||||||
do as_buf(s) |sbuf, n| {
|
do as_buf(s) |sbuf, n| {
|
||||||
assert (begin <= end);
|
|
||||||
assert (end <= n);
|
|
||||||
|
|
||||||
let mut v = ~[];
|
|
||||||
vec::reserve(v, end - begin + 1u);
|
|
||||||
unsafe {
|
|
||||||
do vec::as_buf(v) |vbuf, _vlen| {
|
|
||||||
let src = ptr::offset(sbuf, begin);
|
|
||||||
ptr::memcpy(vbuf, src, end - begin);
|
|
||||||
}
|
|
||||||
vec::unsafe::set_len(v, end - begin);
|
|
||||||
vec::push(v, 0u8);
|
|
||||||
::unsafe::transmute(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes a bytewise (not UTF-8) view from a string.
|
|
||||||
*
|
|
||||||
* Returns the substring from [`begin`..`end`).
|
|
||||||
*
|
|
||||||
* # Failure
|
|
||||||
*
|
|
||||||
* If begin is greater than end.
|
|
||||||
* If end is greater than the length of the string.
|
|
||||||
*/
|
|
||||||
#[inline]
|
|
||||||
unsafe fn view_bytes(s: &str, begin: uint, end: uint) -> &str {
|
|
||||||
do as_buf(s) |sbuf, n| {
|
|
||||||
assert (begin <= end);
|
assert (begin <= end);
|
||||||
assert (end <= n);
|
assert (end <= n);
|
||||||
|
|
||||||
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
|
let mut v = ~[];
|
||||||
::unsafe::reinterpret_cast(tuple)
|
vec::reserve(v, end - begin + 1u);
|
||||||
}
|
unsafe {
|
||||||
}
|
do vec::as_buf(v) |vbuf, _vlen| {
|
||||||
|
let src = ptr::offset(sbuf, begin);
|
||||||
|
ptr::memcpy(vbuf, src, end - begin);
|
||||||
|
}
|
||||||
|
vec::unsafe::set_len(v, end - begin);
|
||||||
|
vec::push(v, 0u8);
|
||||||
|
::unsafe::transmute(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Appends a byte to a string. (Not UTF-8 safe).
|
/**
|
||||||
unsafe fn push_byte(&s: ~str, b: u8) {
|
* Takes a bytewise (not UTF-8) view from a string.
|
||||||
rustrt::rust_str_push(s, b);
|
*
|
||||||
}
|
* Returns the substring from [`begin`..`end`).
|
||||||
|
*
|
||||||
|
* # Failure
|
||||||
|
*
|
||||||
|
* If begin is greater than end.
|
||||||
|
* If end is greater than the length of the string.
|
||||||
|
*/
|
||||||
|
#[inline]
|
||||||
|
unsafe fn view_bytes(s: &str, begin: uint, end: uint) -> &str {
|
||||||
|
do as_buf(s) |sbuf, n| {
|
||||||
|
assert (begin <= end);
|
||||||
|
assert (end <= n);
|
||||||
|
|
||||||
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
|
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
|
||||||
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
|
::unsafe::reinterpret_cast(tuple)
|
||||||
for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
/// Appends a byte to a string. (Not UTF-8 safe).
|
||||||
unsafe fn pop_byte(&s: ~str) -> u8 {
|
unsafe fn push_byte(&s: ~str, b: u8) {
|
||||||
let len = len(s);
|
rustrt::rust_str_push(s, b);
|
||||||
assert (len > 0u);
|
}
|
||||||
let b = s[len - 1u];
|
|
||||||
unsafe { set_len(s, len - 1u) };
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Removes the first byte from a string and returns it. (Not UTF-8 safe).
|
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
|
||||||
unsafe fn shift_byte(&s: ~str) -> u8 {
|
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
|
||||||
let len = len(s);
|
for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); }
|
||||||
assert (len > 0u);
|
}
|
||||||
let b = s[0];
|
|
||||||
s = unsafe { unsafe::slice_bytes(s, 1u, len) };
|
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
||||||
return b;
|
unsafe fn pop_byte(&s: ~str) -> u8 {
|
||||||
}
|
let len = len(s);
|
||||||
|
assert (len > 0u);
|
||||||
|
let b = s[len - 1u];
|
||||||
|
unsafe { set_len(s, len - 1u) };
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the first byte from a string and returns it. (Not UTF-8 safe).
|
||||||
|
unsafe fn shift_byte(&s: ~str) -> u8 {
|
||||||
|
let len = len(s);
|
||||||
|
assert (len > 0u);
|
||||||
|
let b = s[0];
|
||||||
|
s = unsafe { unsafe::slice_bytes(s, 1u, len) };
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the length of the string and adds the null terminator
|
/// Sets the length of the string and adds the null terminator
|
||||||
unsafe fn set_len(&v: ~str, new_len: uint) {
|
unsafe fn set_len(&v: ~str, new_len: uint) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue