File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -141,14 +141,18 @@ impl String {
141
141
/// ```
142
142
#[ stable]
143
143
pub fn from_utf8_lossy < ' a > ( v : & ' a [ u8 ] ) -> CowString < ' a > {
144
+ let mut i = 0 ;
144
145
match str:: from_utf8 ( v) {
145
146
Ok ( s) => return Cow :: Borrowed ( s) ,
146
- Err ( ..) => { }
147
+ Err ( e) => {
148
+ if let Utf8Error :: InvalidByte ( firstbad) = e {
149
+ i = firstbad;
150
+ }
151
+ }
147
152
}
148
153
149
154
static TAG_CONT_U8 : u8 = 128u8 ;
150
155
static REPLACEMENT : & ' static [ u8 ] = b"\xEF \xBF \xBD " ; // U+FFFD in UTF-8
151
- let mut i = 0 ;
152
156
let total = v. len ( ) ;
153
157
fn unsafe_get ( xs : & [ u8 ] , i : uint ) -> u8 {
154
158
unsafe { * xs. get_unchecked ( i) }
@@ -172,7 +176,7 @@ impl String {
172
176
// subseqidx is the index of the first byte of the subsequence we're looking at.
173
177
// It's used to copy a bunch of contiguous good codepoints at once instead of copying
174
178
// them one by one.
175
- let mut subseqidx = 0 ;
179
+ let mut subseqidx = i ;
176
180
177
181
while i < total {
178
182
let i_ = i;
You can’t perform that action at this time.
0 commit comments