Skip to content

Commit ab72744

Browse files
ericktnikomatsakis
authored andcommitted
---
yaml --- r: 30123 b: refs/heads/incoming c: 1dc92d4 h: refs/heads/master i: 30121: eb3d274 30119: 45f6c84 v: v3
1 parent f06ecd8 commit ab72744

File tree

2 files changed

+75
-75
lines changed

2 files changed

+75
-75
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 5d56da1678c00ccff2c4c680de3f2245deef172a
9+
refs/heads/incoming: 1dc92d44be45f125265f98914dc3b5ee9b7e77a2
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/str.rs

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,83 +1859,83 @@ mod unsafe {
18591859
/// Converts a byte to a string.
18601860
unsafe fn from_byte(u: u8) -> ~str { unsafe::from_bytes([u]) }
18611861

1862-
/**
1863-
* Takes a bytewise (not UTF-8) slice from a string.
1864-
*
1865-
* Returns the substring from [`begin`..`end`).
1866-
*
1867-
* # Failure
1868-
*
1869-
* If begin is greater than end.
1870-
* If end is greater than the length of the string.
1871-
*/
1872-
unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> ~str {
1873-
do as_buf(s) |sbuf, n| {
1874-
assert (begin <= end);
1875-
assert (end <= n);
1876-
1877-
let mut v = ~[];
1878-
vec::reserve(v, end - begin + 1u);
1879-
unsafe {
1880-
do vec::as_buf(v) |vbuf, _vlen| {
1881-
let src = ptr::offset(sbuf, begin);
1882-
ptr::memcpy(vbuf, src, end - begin);
1883-
}
1884-
vec::unsafe::set_len(v, end - begin);
1885-
vec::push(v, 0u8);
1886-
::unsafe::transmute(v)
1887-
}
1888-
}
1889-
}
1890-
1891-
/**
1892-
* Takes a bytewise (not UTF-8) view from a string.
1893-
*
1894-
* Returns the substring from [`begin`..`end`).
1895-
*
1896-
* # Failure
1897-
*
1898-
* If begin is greater than end.
1899-
* If end is greater than the length of the string.
1900-
*/
1901-
#[inline]
1902-
unsafe fn view_bytes(s: &str, begin: uint, end: uint) -> &str {
1903-
do as_buf(s) |sbuf, n| {
1862+
/**
1863+
* Takes a bytewise (not UTF-8) slice from a string.
1864+
*
1865+
* Returns the substring from [`begin`..`end`).
1866+
*
1867+
* # Failure
1868+
*
1869+
* If begin is greater than end.
1870+
* If end is greater than the length of the string.
1871+
*/
1872+
unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> ~str {
1873+
do as_buf(s) |sbuf, n| {
19041874
assert (begin <= end);
19051875
assert (end <= n);
19061876

1907-
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
1908-
::unsafe::reinterpret_cast(tuple)
1909-
}
1910-
}
1911-
1912-
/// Appends a byte to a string. (Not UTF-8 safe).
1913-
unsafe fn push_byte(&s: ~str, b: u8) {
1914-
rustrt::rust_str_push(s, b);
1915-
}
1916-
1917-
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
1918-
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
1919-
for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); }
1920-
}
1921-
1922-
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
1923-
unsafe fn pop_byte(&s: ~str) -> u8 {
1924-
let len = len(s);
1925-
assert (len > 0u);
1926-
let b = s[len - 1u];
1927-
unsafe { set_len(s, len - 1u) };
1928-
return b;
1929-
}
1930-
1931-
/// Removes the first byte from a string and returns it. (Not UTF-8 safe).
1932-
unsafe fn shift_byte(&s: ~str) -> u8 {
1933-
let len = len(s);
1934-
assert (len > 0u);
1935-
let b = s[0];
1936-
s = unsafe { unsafe::slice_bytes(s, 1u, len) };
1937-
return b;
1938-
}
1877+
let mut v = ~[];
1878+
vec::reserve(v, end - begin + 1u);
1879+
unsafe {
1880+
do vec::as_buf(v) |vbuf, _vlen| {
1881+
let src = ptr::offset(sbuf, begin);
1882+
ptr::memcpy(vbuf, src, end - begin);
1883+
}
1884+
vec::unsafe::set_len(v, end - begin);
1885+
vec::push(v, 0u8);
1886+
::unsafe::transmute(v)
1887+
}
1888+
}
1889+
}
1890+
1891+
/**
1892+
* Takes a bytewise (not UTF-8) view from a string.
1893+
*
1894+
* Returns the substring from [`begin`..`end`).
1895+
*
1896+
* # Failure
1897+
*
1898+
* If begin is greater than end.
1899+
* If end is greater than the length of the string.
1900+
*/
1901+
#[inline]
1902+
unsafe fn view_bytes(s: &str, begin: uint, end: uint) -> &str {
1903+
do as_buf(s) |sbuf, n| {
1904+
assert (begin <= end);
1905+
assert (end <= n);
1906+
1907+
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
1908+
::unsafe::reinterpret_cast(tuple)
1909+
}
1910+
}
1911+
1912+
/// Appends a byte to a string. (Not UTF-8 safe).
1913+
unsafe fn push_byte(&s: ~str, b: u8) {
1914+
rustrt::rust_str_push(s, b);
1915+
}
1916+
1917+
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
1918+
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
1919+
for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); }
1920+
}
1921+
1922+
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
1923+
unsafe fn pop_byte(&s: ~str) -> u8 {
1924+
let len = len(s);
1925+
assert (len > 0u);
1926+
let b = s[len - 1u];
1927+
unsafe { set_len(s, len - 1u) };
1928+
return b;
1929+
}
1930+
1931+
/// Removes the first byte from a string and returns it. (Not UTF-8 safe).
1932+
unsafe fn shift_byte(&s: ~str) -> u8 {
1933+
let len = len(s);
1934+
assert (len > 0u);
1935+
let b = s[0];
1936+
s = unsafe { unsafe::slice_bytes(s, 1u, len) };
1937+
return b;
1938+
}
19391939

19401940
/// Sets the length of the string and adds the null terminator
19411941
unsafe fn set_len(&v: ~str, new_len: uint) {

0 commit comments

Comments
 (0)