@@ -235,54 +235,49 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
235
235
pub trait DoubleEndedSearcher < ' a > : ReverseSearcher < ' a > { }
236
236
237
237
/////////////////////////////////////////////////////////////////////////////
238
- // Impl for a CharEq wrapper
238
+ // Impl for a MultiCharEq wrapper
239
239
/////////////////////////////////////////////////////////////////////////////
240
240
241
241
#[ doc( hidden) ]
242
- trait CharEq {
242
+ trait MultiCharEq {
243
243
fn matches ( & mut self , c : char ) -> bool ;
244
244
}
245
245
246
- impl CharEq for char {
247
- #[ inline]
248
- fn matches ( & mut self , c : char ) -> bool { * self == c }
249
- }
250
-
251
- impl < F > CharEq for F where F : FnMut ( char ) -> bool {
246
+ impl < F > MultiCharEq for F where F : FnMut ( char ) -> bool {
252
247
#[ inline]
253
248
fn matches ( & mut self , c : char ) -> bool { ( * self ) ( c) }
254
249
}
255
250
256
- impl < ' a > CharEq for & ' a [ char ] {
251
+ impl < ' a > MultiCharEq for & ' a [ char ] {
257
252
#[ inline]
258
253
fn matches ( & mut self , c : char ) -> bool {
259
- self . iter ( ) . any ( |& m| { let mut m = m ; m . matches ( c ) } )
254
+ self . iter ( ) . any ( |& m| { m == c } )
260
255
}
261
256
}
262
257
263
- struct CharEqPattern < C : CharEq > ( C ) ;
258
+ struct MultiCharEqPattern < C : MultiCharEq > ( C ) ;
264
259
265
260
#[ derive( Clone , Debug ) ]
266
- struct CharEqSearcher < ' a , C : CharEq > {
261
+ struct MultiCharEqSearcher < ' a , C : MultiCharEq > {
267
262
char_eq : C ,
268
263
haystack : & ' a str ,
269
264
char_indices : super :: CharIndices < ' a > ,
270
265
}
271
266
272
- impl < ' a , C : CharEq > Pattern < ' a > for CharEqPattern < C > {
273
- type Searcher = CharEqSearcher < ' a , C > ;
267
+ impl < ' a , C : MultiCharEq > Pattern < ' a > for MultiCharEqPattern < C > {
268
+ type Searcher = MultiCharEqSearcher < ' a , C > ;
274
269
275
270
#[ inline]
276
- fn into_searcher ( self , haystack : & ' a str ) -> CharEqSearcher < ' a , C > {
277
- CharEqSearcher {
271
+ fn into_searcher ( self , haystack : & ' a str ) -> MultiCharEqSearcher < ' a , C > {
272
+ MultiCharEqSearcher {
278
273
haystack,
279
274
char_eq : self . 0 ,
280
275
char_indices : haystack. char_indices ( ) ,
281
276
}
282
277
}
283
278
}
284
279
285
- unsafe impl < ' a , C : CharEq > Searcher < ' a > for CharEqSearcher < ' a , C > {
280
+ unsafe impl < ' a , C : MultiCharEq > Searcher < ' a > for MultiCharEqSearcher < ' a , C > {
286
281
#[ inline]
287
282
fn haystack ( & self ) -> & ' a str {
288
283
self . haystack
@@ -307,7 +302,7 @@ unsafe impl<'a, C: CharEq> Searcher<'a> for CharEqSearcher<'a, C> {
307
302
}
308
303
}
309
304
310
- unsafe impl < ' a , C : CharEq > ReverseSearcher < ' a > for CharEqSearcher < ' a , C > {
305
+ unsafe impl < ' a , C : MultiCharEq > ReverseSearcher < ' a > for MultiCharEqSearcher < ' a , C > {
311
306
#[ inline]
312
307
fn next_back ( & mut self ) -> SearchStep {
313
308
let s = & mut self . char_indices ;
@@ -327,7 +322,7 @@ unsafe impl<'a, C: CharEq> ReverseSearcher<'a> for CharEqSearcher<'a, C> {
327
322
}
328
323
}
329
324
330
- impl < ' a , C : CharEq > DoubleEndedSearcher < ' a > for CharEqSearcher < ' a , C > { }
325
+ impl < ' a , C : MultiCharEq > DoubleEndedSearcher < ' a > for MultiCharEqSearcher < ' a , C > { }
331
326
332
327
/////////////////////////////////////////////////////////////////////////////
333
328
@@ -400,14 +395,40 @@ macro_rules! searcher_methods {
400
395
401
396
/// Associated type for `<char as Pattern<'a>>::Searcher`.
402
397
#[ derive( Clone , Debug ) ]
403
- pub struct CharSearcher < ' a > ( < CharEqPattern < char > as Pattern < ' a > > :: Searcher ) ;
398
+ pub struct CharSearcher < ' a > ( & ' a str ) ;
404
399
405
400
unsafe impl < ' a > Searcher < ' a > for CharSearcher < ' a > {
406
- searcher_methods ! ( forward) ;
401
+ #[ inline]
402
+ fn haystack ( & self ) -> & ' a str {
403
+ unimplemented ! ( ) ;
404
+ }
405
+ #[ inline]
406
+ fn next ( & mut self ) -> SearchStep {
407
+ unimplemented ! ( ) ;
408
+ }
409
+ #[ inline]
410
+ fn next_match ( & mut self ) -> Option < ( usize , usize ) > {
411
+ unimplemented ! ( ) ;
412
+ }
413
+ #[ inline]
414
+ fn next_reject ( & mut self ) -> Option < ( usize , usize ) > {
415
+ unimplemented ! ( ) ;
416
+ }
407
417
}
408
418
409
419
unsafe impl < ' a > ReverseSearcher < ' a > for CharSearcher < ' a > {
410
- searcher_methods ! ( reverse) ;
420
+ #[ inline]
421
+ fn next_back ( & mut self ) -> SearchStep {
422
+ unimplemented ! ( ) ;
423
+ }
424
+ #[ inline]
425
+ fn next_match_back ( & mut self ) -> Option < ( usize , usize ) > {
426
+ unimplemented ! ( ) ;
427
+ }
428
+ #[ inline]
429
+ fn next_reject_back ( & mut self ) -> Option < ( usize , usize ) > {
430
+ unimplemented ! ( ) ;
431
+ }
411
432
}
412
433
413
434
impl < ' a > DoubleEndedSearcher < ' a > for CharSearcher < ' a > { }
@@ -418,7 +439,7 @@ impl<'a> Pattern<'a> for char {
418
439
419
440
#[ inline]
420
441
fn into_searcher ( self , haystack : & ' a str ) -> Self :: Searcher {
421
- CharSearcher ( CharEqPattern ( self ) . into_searcher ( haystack) )
442
+ CharSearcher ( haystack)
422
443
}
423
444
424
445
#[ inline]
@@ -433,13 +454,21 @@ impl<'a> Pattern<'a> for char {
433
454
434
455
#[ inline]
435
456
fn is_prefix_of ( self , haystack : & ' a str ) -> bool {
436
- CharEqPattern ( self ) . is_prefix_of ( haystack)
457
+ if let Some ( ch) = haystack. chars ( ) . next ( ) {
458
+ self == ch
459
+ } else {
460
+ false
461
+ }
437
462
}
438
463
439
464
#[ inline]
440
465
fn is_suffix_of ( self , haystack : & ' a str ) -> bool where Self :: Searcher : ReverseSearcher < ' a >
441
466
{
442
- CharEqPattern ( self ) . is_suffix_of ( haystack)
467
+ if let Some ( ch) = haystack. chars ( ) . next_back ( ) {
468
+ self == ch
469
+ } else {
470
+ false
471
+ }
443
472
}
444
473
}
445
474
@@ -451,7 +480,7 @@ impl<'a> Pattern<'a> for char {
451
480
452
481
/// Associated type for `<&[char] as Pattern<'a>>::Searcher`.
453
482
#[ derive( Clone , Debug ) ]
454
- pub struct CharSliceSearcher < ' a , ' b > ( <CharEqPattern < & ' b [ char ] > as Pattern < ' a > >:: Searcher ) ;
483
+ pub struct CharSliceSearcher < ' a , ' b > ( <MultiCharEqPattern < & ' b [ char ] > as Pattern < ' a > >:: Searcher ) ;
455
484
456
485
unsafe impl < ' a , ' b > Searcher < ' a > for CharSliceSearcher < ' a , ' b > {
457
486
searcher_methods ! ( forward) ;
@@ -465,7 +494,7 @@ impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
465
494
466
495
/// Searches for chars that are equal to any of the chars in the array
467
496
impl < ' a , ' b > Pattern < ' a > for & ' b [ char ] {
468
- pattern_methods ! ( CharSliceSearcher <' a, ' b>, CharEqPattern , CharSliceSearcher ) ;
497
+ pattern_methods ! ( CharSliceSearcher <' a, ' b>, MultiCharEqPattern , CharSliceSearcher ) ;
469
498
}
470
499
471
500
/////////////////////////////////////////////////////////////////////////////
@@ -474,7 +503,7 @@ impl<'a, 'b> Pattern<'a> for &'b [char] {
474
503
475
504
/// Associated type for `<F as Pattern<'a>>::Searcher`.
476
505
#[ derive( Clone ) ]
477
- pub struct CharPredicateSearcher < ' a , F > ( <CharEqPattern < F > as Pattern < ' a > >:: Searcher )
506
+ pub struct CharPredicateSearcher < ' a , F > ( <MultiCharEqPattern < F > as Pattern < ' a > >:: Searcher )
478
507
where F : FnMut ( char ) -> bool ;
479
508
480
509
impl < ' a , F > fmt:: Debug for CharPredicateSearcher < ' a , F >
@@ -504,7 +533,7 @@ impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F>
504
533
505
534
/// Searches for chars that match the given predicate
506
535
impl < ' a , F > Pattern < ' a > for F where F : FnMut ( char ) -> bool {
507
- pattern_methods ! ( CharPredicateSearcher <' a, F >, CharEqPattern , CharPredicateSearcher ) ;
536
+ pattern_methods ! ( CharPredicateSearcher <' a, F >, MultiCharEqPattern , CharPredicateSearcher ) ;
508
537
}
509
538
510
539
/////////////////////////////////////////////////////////////////////////////
0 commit comments