@@ -279,7 +279,7 @@ pub struct Parser<'a, L: Language> {
279279 src : & ' a str ,
280280 index : usize ,
281281 language_items : & ' static [ ParseItem ] ,
282- _marker : PhantomData < L >
282+ _marker : PhantomData < L > ,
283283}
284284
285285// most this is only used in tests atm!
@@ -290,7 +290,7 @@ impl<L: Language> Parser<'_, L> {
290290 src,
291291 language_items : L :: PARSE_ITEMS ,
292292 index : 0 ,
293- _marker : PhantomData :: default ( )
293+ _marker : PhantomData :: default ( ) ,
294294 }
295295 }
296296
@@ -304,35 +304,40 @@ impl<L: Language> Parser<'_, L> {
304304 . find_map ( |i| Some ( ( i, items[ i] . begin ( ) . matches ( src) ?) ) )
305305 . and_then ( |( i, matches) | {
306306 ( matches[ 2 ] . end ..src. len ( ) ) . find_map ( |b| {
307- Some ( (
308- i,
309- b,
310- if items[ i] . is_key_matched ( ) {
311- items[ i] . end ( ) . matches_with_key (
312- & src[ b..] ,
313- & src[ matches[ 1 ] . start ..matches[ 1 ] . end ] ,
314- ) ?
315- } else {
316- items[ i] . end ( ) . matches ( & src[ b..] ) ?
317- } ,
318- ) )
307+ if src. is_char_boundary ( b) {
308+ Some ( (
309+ i,
310+ b,
311+ if items[ i] . is_key_matched ( ) {
312+ items[ i] . end ( ) . matches_with_key (
313+ & src[ b..] ,
314+ & src[ matches[ 1 ] . start ..matches[ 1 ] . end ] ,
315+ ) ?
316+ } else {
317+ items[ i] . end ( ) . matches ( & src[ b..] ) ?
318+ } ,
319+ ) )
320+ } else {
321+ None
322+ }
319323 } )
320324 } )
321325 {
322- Ok ( items[ i] . to_parse_output ( & src[ 0 ..b + end_matches[ 2 ] . end ] ) )
326+ Ok ( items[ i] . to_parse_output ( & src[ ..b + end_matches[ 2 ] . end ] ) )
323327 } else if let Some ( end) = ( 1 ..=src. len ( ) ) . find ( |& idx| {
324- idx == src. len ( )
325- || src[ idx..] . starts_with ( '\n' )
326- || items
327- . iter ( )
328- . find_map ( |i| i. begin ( ) . matches ( & src[ idx..] ) )
329- . is_some ( )
328+ src. is_char_boundary ( idx)
329+ && ( idx == src. len ( )
330+ || src[ idx..] . starts_with ( '\n' )
331+ || items
332+ . iter ( )
333+ . find_map ( |i| i. begin ( ) . matches ( & src[ idx..] ) )
334+ . is_some ( ) )
330335 } ) {
331336 // if it's not a range then it's a source line
332337 if end == 0 {
333338 Err ( "Failed to parse, for some random reason, pls lookie here" ) ?;
334339 }
335- Ok ( ParseOutput :: Source ( & src[ 0 ..end] ) )
340+ Ok ( ParseOutput :: Source ( & src[ ..end] ) )
336341 } else {
337342 Err ( "Failed to parse the rest." ) ?
338343 }
0 commit comments