@@ -1859,83 +1859,83 @@ mod unsafe {
1859
1859
/// Converts a byte to a string.
1860
1860
unsafe fn from_byte ( u : u8 ) -> ~str { unsafe :: from_bytes ( [ u] ) }
1861
1861
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 + 1 u) ;
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| {
1904
1874
assert ( begin <= end) ;
1905
1875
assert ( end <= n) ;
1906
1876
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 > 0 u) ;
1926
- let b = s[ len - 1 u] ;
1927
- unsafe { set_len ( s, len - 1 u) } ;
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 > 0 u) ;
1935
- let b = s[ 0 ] ;
1936
- s = unsafe { unsafe :: slice_bytes ( s, 1 u, len) } ;
1937
- return b;
1938
- }
1877
+ let mut v = ~[ ] ;
1878
+ vec:: reserve ( v, end - begin + 1 u) ;
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 > 0 u) ;
1926
+ let b = s[ len - 1 u] ;
1927
+ unsafe { set_len ( s, len - 1 u) } ;
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 > 0 u) ;
1935
+ let b = s[ 0 ] ;
1936
+ s = unsafe { unsafe :: slice_bytes ( s, 1 u, len) } ;
1937
+ return b;
1938
+ }
1939
1939
1940
1940
/// Sets the length of the string and adds the null terminator
1941
1941
unsafe fn set_len ( & v: ~str , new_len : uint ) {
0 commit comments