File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -160,10 +160,8 @@ impl CharReader {
160
160
if let Some ( Ok ( c) ) = char:: decode_utf16 ( [ u16:: from_be_bytes ( buf[ ..2 ] . try_into ( ) . unwrap ( ) ) ] ) . next ( ) {
161
161
return Ok ( Some ( c) ) ;
162
162
}
163
- } else if pos == 4 { // surrogate
164
- return char:: decode_utf16 ( [ u16:: from_be_bytes ( buf[ ..2 ] . try_into ( ) . unwrap ( ) ) , u16:: from_be_bytes ( buf[ 2 ..4 ] . try_into ( ) . unwrap ( ) ) ] )
165
- . next ( ) . transpose ( )
166
- . map_err ( |e| CharReadError :: Io ( io:: Error :: new ( io:: ErrorKind :: InvalidData , e) ) ) ;
163
+ } else if pos == 4 {
164
+ return Self :: surrogate ( [ u16:: from_be_bytes ( buf[ ..2 ] . try_into ( ) . unwrap ( ) ) , u16:: from_be_bytes ( buf[ 2 ..4 ] . try_into ( ) . unwrap ( ) ) ] ) ;
167
165
}
168
166
} ,
169
167
Encoding :: Utf16Le => {
@@ -173,10 +171,8 @@ impl CharReader {
173
171
if let Some ( Ok ( c) ) = char:: decode_utf16 ( [ u16:: from_le_bytes ( buf[ ..2 ] . try_into ( ) . unwrap ( ) ) ] ) . next ( ) {
174
172
return Ok ( Some ( c) ) ;
175
173
}
176
- } else if pos == 4 { // surrogate
177
- return char:: decode_utf16 ( [ u16:: from_le_bytes ( buf[ ..2 ] . try_into ( ) . unwrap ( ) ) , u16:: from_le_bytes ( buf[ 2 ..4 ] . try_into ( ) . unwrap ( ) ) ] )
178
- . next ( ) . transpose ( )
179
- . map_err ( |e| CharReadError :: Io ( io:: Error :: new ( io:: ErrorKind :: InvalidData , e) ) ) ;
174
+ } else if pos == 4 {
175
+ return Self :: surrogate ( [ u16:: from_le_bytes ( buf[ ..2 ] . try_into ( ) . unwrap ( ) ) , u16:: from_le_bytes ( buf[ 2 ..4 ] . try_into ( ) . unwrap ( ) ) ] ) ;
180
176
}
181
177
} ,
182
178
}
@@ -214,6 +210,11 @@ impl CharReader {
214
210
}
215
211
None
216
212
}
213
+
214
+ fn surrogate ( buf : [ u16 ; 2 ] ) -> Result < Option < char > , CharReadError > {
215
+ char:: decode_utf16 ( buf) . next ( ) . transpose ( )
216
+ . map_err ( |e| CharReadError :: Io ( io:: Error :: new ( io:: ErrorKind :: InvalidData , e) ) )
217
+ }
217
218
}
218
219
219
220
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments