@@ -234,6 +234,90 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
234234/// `"[aa]a"` or `"a[aa]"`, depending from which side it is searched.
235235pub trait DoubleEndedSearcher < ' a > : ReverseSearcher < ' a > { }
236236
237+
238+ /////////////////////////////////////////////////////////////////////////////
239+ // Impl for char
240+ /////////////////////////////////////////////////////////////////////////////
241+
242+ /// Associated type for `<char as Pattern<'a>>::Searcher`.
243+ #[ derive( Clone , Debug ) ]
244+ pub struct CharSearcher < ' a > ( & ' a str ) ;
245+
246+ unsafe impl < ' a > Searcher < ' a > for CharSearcher < ' a > {
247+ #[ inline]
248+ fn haystack ( & self ) -> & ' a str {
249+ unimplemented ! ( ) ;
250+ }
251+ #[ inline]
252+ fn next ( & mut self ) -> SearchStep {
253+ unimplemented ! ( ) ;
254+ }
255+ #[ inline]
256+ fn next_match ( & mut self ) -> Option < ( usize , usize ) > {
257+ unimplemented ! ( ) ;
258+ }
259+ #[ inline]
260+ fn next_reject ( & mut self ) -> Option < ( usize , usize ) > {
261+ unimplemented ! ( ) ;
262+ }
263+ }
264+
265+ unsafe impl < ' a > ReverseSearcher < ' a > for CharSearcher < ' a > {
266+ #[ inline]
267+ fn next_back ( & mut self ) -> SearchStep {
268+ unimplemented ! ( ) ;
269+ }
270+ #[ inline]
271+ fn next_match_back ( & mut self ) -> Option < ( usize , usize ) > {
272+ unimplemented ! ( ) ;
273+ }
274+ #[ inline]
275+ fn next_reject_back ( & mut self ) -> Option < ( usize , usize ) > {
276+ unimplemented ! ( ) ;
277+ }
278+ }
279+
280+ impl < ' a > DoubleEndedSearcher < ' a > for CharSearcher < ' a > { }
281+
282+ /// Searches for chars that are equal to a given char
283+ impl < ' a > Pattern < ' a > for char {
284+ type Searcher = CharSearcher < ' a > ;
285+
286+ #[ inline]
287+ fn into_searcher ( self , haystack : & ' a str ) -> Self :: Searcher {
288+ CharSearcher ( haystack)
289+ }
290+
291+ #[ inline]
292+ fn is_contained_in ( self , haystack : & ' a str ) -> bool {
293+ if ( self as u32 ) < 128 {
294+ haystack. as_bytes ( ) . contains ( & ( self as u8 ) )
295+ } else {
296+ let mut buffer = [ 0u8 ; 4 ] ;
297+ self . encode_utf8 ( & mut buffer) . is_contained_in ( haystack)
298+ }
299+ }
300+
301+ #[ inline]
302+ fn is_prefix_of ( self , haystack : & ' a str ) -> bool {
303+ if let Some ( ch) = haystack. chars ( ) . next ( ) {
304+ self == ch
305+ } else {
306+ false
307+ }
308+ }
309+
310+ #[ inline]
311+ fn is_suffix_of ( self , haystack : & ' a str ) -> bool where Self :: Searcher : ReverseSearcher < ' a >
312+ {
313+ if let Some ( ch) = haystack. chars ( ) . next_back ( ) {
314+ self == ch
315+ } else {
316+ false
317+ }
318+ }
319+ }
320+
237321/////////////////////////////////////////////////////////////////////////////
238322// Impl for a MultiCharEq wrapper
239323/////////////////////////////////////////////////////////////////////////////
@@ -389,89 +473,6 @@ macro_rules! searcher_methods {
389473 }
390474}
391475
392- /////////////////////////////////////////////////////////////////////////////
393- // Impl for char
394- /////////////////////////////////////////////////////////////////////////////
395-
396- /// Associated type for `<char as Pattern<'a>>::Searcher`.
397- #[ derive( Clone , Debug ) ]
398- pub struct CharSearcher < ' a > ( & ' a str ) ;
399-
400- unsafe impl < ' a > Searcher < ' a > for CharSearcher < ' a > {
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- }
417- }
418-
419- unsafe impl < ' a > ReverseSearcher < ' a > for CharSearcher < ' a > {
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- }
432- }
433-
434- impl < ' a > DoubleEndedSearcher < ' a > for CharSearcher < ' a > { }
435-
436- /// Searches for chars that are equal to a given char
437- impl < ' a > Pattern < ' a > for char {
438- type Searcher = CharSearcher < ' a > ;
439-
440- #[ inline]
441- fn into_searcher ( self , haystack : & ' a str ) -> Self :: Searcher {
442- CharSearcher ( haystack)
443- }
444-
445- #[ inline]
446- fn is_contained_in ( self , haystack : & ' a str ) -> bool {
447- if ( self as u32 ) < 128 {
448- haystack. as_bytes ( ) . contains ( & ( self as u8 ) )
449- } else {
450- let mut buffer = [ 0u8 ; 4 ] ;
451- self . encode_utf8 ( & mut buffer) . is_contained_in ( haystack)
452- }
453- }
454-
455- #[ inline]
456- fn is_prefix_of ( self , haystack : & ' a str ) -> bool {
457- if let Some ( ch) = haystack. chars ( ) . next ( ) {
458- self == ch
459- } else {
460- false
461- }
462- }
463-
464- #[ inline]
465- fn is_suffix_of ( self , haystack : & ' a str ) -> bool where Self :: Searcher : ReverseSearcher < ' a >
466- {
467- if let Some ( ch) = haystack. chars ( ) . next_back ( ) {
468- self == ch
469- } else {
470- false
471- }
472- }
473- }
474-
475476/////////////////////////////////////////////////////////////////////////////
476477// Impl for &[char]
477478/////////////////////////////////////////////////////////////////////////////
0 commit comments