@@ -751,7 +751,7 @@ impl String {
751
751
return Err ( FromUtf16Error ( ( ) ) ) ;
752
752
}
753
753
match ( cfg ! ( target_endian = "little" ) , unsafe { v. align_to :: < u16 > ( ) } ) {
754
- ( true , ( & [ ] , v, & [ ] ) ) => Self :: from_utf16 ( v) ,
754
+ ( true , ( [ ] , v, [ ] ) ) => Self :: from_utf16 ( v) ,
755
755
_ => decode_utf16 ( v. array_chunks :: < 2 > ( ) . copied ( ) . map ( u16:: from_le_bytes) )
756
756
. collect :: < Result < _ , _ > > ( )
757
757
. map_err ( |_| FromUtf16Error ( ( ) ) ) ,
@@ -787,14 +787,18 @@ impl String {
787
787
#[ unstable( feature = "str_from_utf16_endian" , issue = "none" , reason = "recently added" ) ]
788
788
pub fn from_utf16le_lossy ( v : & [ u8 ] ) -> String {
789
789
match ( cfg ! ( target_endian = "little" ) , unsafe { v. align_to :: < u16 > ( ) } ) {
790
- ( true , ( & [ ] , v, & [ ] ) ) => Self :: from_utf16_lossy ( v) ,
791
- ( true , ( & [ ] , v, & [ _remainder] ) ) => Self :: from_utf16_lossy ( v) + "\u{FFFD} " ,
790
+ ( true , ( [ ] , v, [ ] ) ) => Self :: from_utf16_lossy ( v) ,
791
+ ( true , ( [ ] , v, [ _remainder] ) ) => Self :: from_utf16_lossy ( v) + "\u{FFFD} " ,
792
792
_ => {
793
793
let mut iter = v. array_chunks :: < 2 > ( ) ;
794
794
let string = decode_utf16 ( iter. by_ref ( ) . copied ( ) . map ( u16:: from_le_bytes) )
795
795
. map ( |r| r. unwrap_or ( REPLACEMENT_CHARACTER ) )
796
796
. collect ( ) ;
797
- if iter. remainder ( ) . is_empty ( ) { string } else { string + "\u{FFFD} " }
797
+ if iter. remainder ( ) . is_empty ( ) {
798
+ string
799
+ } else {
800
+ string + "\u{FFFD} "
801
+ }
798
802
}
799
803
}
800
804
}
@@ -826,7 +830,7 @@ impl String {
826
830
return Err ( FromUtf16Error ( ( ) ) ) ;
827
831
}
828
832
match ( cfg ! ( target_endian = "big" ) , unsafe { v. align_to :: < u16 > ( ) } ) {
829
- ( true , ( & [ ] , v, & [ ] ) ) => Self :: from_utf16 ( v) ,
833
+ ( true , ( [ ] , v, [ ] ) ) => Self :: from_utf16 ( v) ,
830
834
_ => decode_utf16 ( v. array_chunks :: < 2 > ( ) . copied ( ) . map ( u16:: from_be_bytes) )
831
835
. collect :: < Result < _ , _ > > ( )
832
836
. map_err ( |_| FromUtf16Error ( ( ) ) ) ,
@@ -862,14 +866,18 @@ impl String {
862
866
#[ unstable( feature = "str_from_utf16_endian" , issue = "none" , reason = "recently added" ) ]
863
867
pub fn from_utf16be_lossy ( v : & [ u8 ] ) -> String {
864
868
match ( cfg ! ( target_endian = "big" ) , unsafe { v. align_to :: < u16 > ( ) } ) {
865
- ( true , ( & [ ] , v, & [ ] ) ) => Self :: from_utf16_lossy ( v) ,
866
- ( true , ( & [ ] , v, & [ _remainder] ) ) => Self :: from_utf16_lossy ( v) + "\u{FFFD} " ,
869
+ ( true , ( [ ] , v, [ ] ) ) => Self :: from_utf16_lossy ( v) ,
870
+ ( true , ( [ ] , v, [ _remainder] ) ) => Self :: from_utf16_lossy ( v) + "\u{FFFD} " ,
867
871
_ => {
868
872
let mut iter = v. array_chunks :: < 2 > ( ) ;
869
873
let string = decode_utf16 ( iter. by_ref ( ) . copied ( ) . map ( u16:: from_be_bytes) )
870
874
. map ( |r| r. unwrap_or ( REPLACEMENT_CHARACTER ) )
871
875
. collect ( ) ;
872
- if iter. remainder ( ) . is_empty ( ) { string } else { string + "\u{FFFD} " }
876
+ if iter. remainder ( ) . is_empty ( ) {
877
+ string
878
+ } else {
879
+ string + "\u{FFFD} "
880
+ }
873
881
}
874
882
}
875
883
}
0 commit comments