@@ -83,21 +83,6 @@ pub fn from_bytes_owned(vv: ~[u8]) -> ~str {
83
83
}
84
84
}
85
85
86
- /// Convert a vector of bytes to a UTF-8 string.
87
- /// The vector needs to be one byte longer than the string, and end with a 0 byte.
88
- ///
89
- /// Compared to `from_bytes()`, this fn doesn't need to allocate a new owned str.
90
- ///
91
- /// # Failure
92
- ///
93
- /// Fails if invalid UTF-8
94
- /// Fails if not null terminated
95
- pub fn from_bytes_with_null < ' a > ( vv : & ' a [ u8 ] ) -> & ' a str {
96
- assert_eq ! ( vv[ vv. len( ) - 1 ] , 0 ) ;
97
- assert ! ( is_utf8( vv) ) ;
98
- return unsafe { raw:: from_bytes_with_null ( vv) } ;
99
- }
100
-
101
86
/// Converts a vector to a string slice without performing any allocations.
102
87
///
103
88
/// Once the slice has been validated as utf-8, it is transmuted in-place and
@@ -826,13 +811,6 @@ pub mod raw {
826
811
cast:: transmute ( v)
827
812
}
828
813
829
- /// Converts a vector of bytes to a string.
830
- /// The byte slice needs to contain valid utf8 and needs to be one byte longer than
831
- /// the string, if possible ending in a 0 byte.
832
- pub unsafe fn from_bytes_with_null < ' a > ( v : & ' a [ u8 ] ) -> & ' a str {
833
- cast:: transmute ( v)
834
- }
835
-
836
814
/// Converts a byte to a string.
837
815
pub unsafe fn from_byte ( u : u8 ) -> ~str { from_bytes ( [ u] ) }
838
816
@@ -2867,66 +2845,6 @@ mod tests {
2867
2845
assert!(error_happened);
2868
2846
}
2869
2847
2870
- #[test]
2871
- fn test_unsafe_from_bytes_with_null() {
2872
- let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
2873
- let b = unsafe { raw::from_bytes_with_null(a) };
2874
- assert_eq!(b, " AAAAAAA ");
2875
- }
2876
-
2877
- #[test]
2878
- fn test_from_bytes_with_null() {
2879
- let ss = " ศไทย中华Việt Nam ";
2880
- let bb = [0xe0_u8, 0xb8_u8, 0xa8_u8,
2881
- 0xe0_u8, 0xb9_u8, 0x84_u8,
2882
- 0xe0_u8, 0xb8_u8, 0x97_u8,
2883
- 0xe0_u8, 0xb8_u8, 0xa2_u8,
2884
- 0xe4_u8, 0xb8_u8, 0xad_u8,
2885
- 0xe5_u8, 0x8d_u8, 0x8e_u8,
2886
- 0x56_u8, 0x69_u8, 0xe1_u8,
2887
- 0xbb_u8, 0x87_u8, 0x74_u8,
2888
- 0x20_u8, 0x4e_u8, 0x61_u8,
2889
- 0x6d_u8, 0x0_u8];
2890
-
2891
- assert_eq!(ss, from_bytes_with_null(bb));
2892
- }
2893
-
2894
- #[test]
2895
- #[should_fail]
2896
- #[ignore(cfg(windows))]
2897
- fn test_from_bytes_with_null_fail() {
2898
- let bb = [0xff_u8, 0xb8_u8, 0xa8_u8,
2899
- 0xe0_u8, 0xb9_u8, 0x84_u8,
2900
- 0xe0_u8, 0xb8_u8, 0x97_u8,
2901
- 0xe0_u8, 0xb8_u8, 0xa2_u8,
2902
- 0xe4_u8, 0xb8_u8, 0xad_u8,
2903
- 0xe5_u8, 0x8d_u8, 0x8e_u8,
2904
- 0x56_u8, 0x69_u8, 0xe1_u8,
2905
- 0xbb_u8, 0x87_u8, 0x74_u8,
2906
- 0x20_u8, 0x4e_u8, 0x61_u8,
2907
- 0x6d_u8, 0x0_u8];
2908
-
2909
- let _x = from_bytes_with_null(bb);
2910
- }
2911
-
2912
- #[test]
2913
- #[should_fail]
2914
- #[ignore(cfg(windows))]
2915
- fn test_from_bytes_with_null_fail_2() {
2916
- let bb = [0xff_u8, 0xb8_u8, 0xa8_u8,
2917
- 0xe0_u8, 0xb9_u8, 0x84_u8,
2918
- 0xe0_u8, 0xb8_u8, 0x97_u8,
2919
- 0xe0_u8, 0xb8_u8, 0xa2_u8,
2920
- 0xe4_u8, 0xb8_u8, 0xad_u8,
2921
- 0xe5_u8, 0x8d_u8, 0x8e_u8,
2922
- 0x56_u8, 0x69_u8, 0xe1_u8,
2923
- 0xbb_u8, 0x87_u8, 0x74_u8,
2924
- 0x20_u8, 0x4e_u8, 0x61_u8,
2925
- 0x6d_u8, 0x60_u8];
2926
-
2927
- let _x = from_bytes_with_null(bb);
2928
- }
2929
-
2930
2848
#[test]
2931
2849
fn test_from_buf() {
2932
2850
unsafe {
0 commit comments