25
25
html_root_url = "http://doc.rust-lang.org/glob/" ) ]
26
26
#![ cfg_attr( test, deny( warnings) ) ]
27
27
#![ cfg_attr( all( test, windows) , feature( std_misc) ) ]
28
- #![ feature( path, io, core , collections , unicode ) ]
28
+ #![ feature( path, io) ]
29
29
30
30
use std:: ascii:: AsciiExt ;
31
31
use std:: cell:: Cell ;
@@ -251,7 +251,7 @@ impl Iterator for Paths {
251
251
// Shouldn't happen, but we're using -1 as a special index.
252
252
assert ! ( self . dir_patterns. len( ) < -1 as usize ) ;
253
253
254
- fill_todo ( & mut self . todo , self . dir_patterns . as_slice ( ) ,
254
+ fill_todo ( & mut self . todo , & self . dir_patterns ,
255
255
0 , & scope, & self . options ) ;
256
256
}
257
257
}
@@ -285,7 +285,7 @@ impl Iterator for Paths {
285
285
// the path is a directory, so it's a match
286
286
if is_dir ( & path) {
287
287
// push this directory's contents
288
- fill_todo ( & mut self . todo , self . dir_patterns . as_slice ( ) ,
288
+ fill_todo ( & mut self . todo , & self . dir_patterns ,
289
289
next, & path, & self . options ) ;
290
290
291
291
// pattern ends in recursive pattern, so return this
@@ -324,7 +324,7 @@ impl Iterator for Paths {
324
324
return Some ( Ok ( path) ) ;
325
325
}
326
326
} else {
327
- fill_todo ( & mut self . todo , self . dir_patterns . as_slice ( ) ,
327
+ fill_todo ( & mut self . todo , & self . dir_patterns ,
328
328
idx + 1 , & path, & self . options ) ;
329
329
}
330
330
}
@@ -502,7 +502,7 @@ impl Pattern {
502
502
'[' => {
503
503
504
504
if i + 4 <= chars. len ( ) && chars[ i + 1 ] == '!' {
505
- match chars[ i + 3 ..] . position_elem ( & ']' ) {
505
+ match chars[ i + 3 ..] . iter ( ) . position ( |x| * x == ']' ) {
506
506
None => ( ) ,
507
507
Some ( j) => {
508
508
let chars = & chars[ i + 2 .. i + 3 + j] ;
@@ -513,7 +513,7 @@ impl Pattern {
513
513
}
514
514
}
515
515
} else if i + 3 <= chars. len ( ) && chars[ i + 1 ] != '!' {
516
- match chars[ i + 2 ..] . position_elem ( & ']' ) {
516
+ match chars[ i + 2 ..] . iter ( ) . position ( |x| * x == ']' ) {
517
517
None => ( ) ,
518
518
Some ( j) => {
519
519
let cs = parse_char_specifiers ( & chars[ i + 1 ..
@@ -609,9 +609,7 @@ impl Pattern {
609
609
}
610
610
611
611
/// Access the original glob pattern.
612
- pub fn as_str < ' a > ( & ' a self ) -> & ' a str {
613
- self . original . as_slice ( )
614
- }
612
+ pub fn as_str < ' a > ( & ' a self ) -> & ' a str { & self . original }
615
613
616
614
fn matches_from ( & self ,
617
615
prev_char : Option < char > ,
@@ -637,10 +635,9 @@ impl Pattern {
637
635
m => return m,
638
636
}
639
637
640
- let ( c, next) = match file. slice_shift_char ( ) {
641
- None => return EntirePatternDoesntMatch ,
642
- Some ( pair) => pair
643
- } ;
638
+ if file. len ( ) == 0 { return EntirePatternDoesntMatch }
639
+ let c = file. chars ( ) . next ( ) . unwrap ( ) ;
640
+ let next = & file[ c. len_utf8 ( ) ..] ;
644
641
645
642
if let AnySequence = * token {
646
643
if require_literal ( c) {
@@ -653,24 +650,23 @@ impl Pattern {
653
650
}
654
651
}
655
652
_ => {
656
- let ( c, next) = match file. slice_shift_char ( ) {
657
- None => return EntirePatternDoesntMatch ,
658
- Some ( pair) => pair
659
- } ;
653
+ if file. len ( ) == 0 { return EntirePatternDoesntMatch }
654
+ let c = file. chars ( ) . next ( ) . unwrap ( ) ;
655
+ let next = & file[ c. len_utf8 ( ) ..] ;
660
656
661
657
let matches = match * token {
662
658
AnyChar => {
663
659
!require_literal ( c)
664
660
}
665
661
AnyWithin ( ref specifiers) => {
666
662
!require_literal ( c) &&
667
- in_char_specifiers ( specifiers. as_slice ( ) ,
663
+ in_char_specifiers ( & specifiers,
668
664
c,
669
665
options)
670
666
}
671
667
AnyExcept ( ref specifiers) => {
672
668
!require_literal ( c) &&
673
- !in_char_specifiers ( specifiers. as_slice ( ) ,
669
+ !in_char_specifiers ( & specifiers,
674
670
c,
675
671
options)
676
672
}
@@ -740,7 +736,7 @@ fn fill_todo(todo: &mut Vec<Result<(PathBuf, usize), GlobError>>,
740
736
// continue. So instead of passing control back to the iterator,
741
737
// we can just check for that one entry and potentially recurse
742
738
// right away.
743
- let special = "." == s. as_slice ( ) || ".." == s. as_slice ( ) ;
739
+ let special = "." == s || ".." == s;
744
740
let next_path = if curdir { PathBuf :: new ( & s) } else { path. join ( & s) } ;
745
741
if ( special && is_dir) || ( !special && fs:: metadata ( & next_path) . is_ok ( ) ) {
746
742
add ( todo, next_path) ;
@@ -819,8 +815,8 @@ fn in_char_specifiers(specifiers: &[CharSpecifier], c: char, options: &MatchOpti
819
815
let start = start. to_ascii_lowercase ( ) ;
820
816
let end = end. to_ascii_lowercase ( ) ;
821
817
822
- let start_up = start. to_uppercase ( ) ;
823
- let end_up = end. to_uppercase ( ) ;
818
+ let start_up = start. to_uppercase ( ) . next ( ) . unwrap ( ) ;
819
+ let end_up = end. to_uppercase ( ) . next ( ) . unwrap ( ) ;
824
820
825
821
// only allow case insensitive matching when
826
822
// both start and end are within a-z or A-Z
@@ -1036,25 +1032,25 @@ mod test {
1036
1032
1037
1033
let pat = Pattern :: new ( "a[0-9]b" ) . unwrap ( ) ;
1038
1034
for i in 0 ..10 {
1039
- assert ! ( pat. matches( format!( "a{}b" , i) . as_slice ( ) ) ) ;
1035
+ assert ! ( pat. matches( & format!( "a{}b" , i) ) ) ;
1040
1036
}
1041
1037
assert ! ( !pat. matches( "a_b" ) ) ;
1042
1038
1043
1039
let pat = Pattern :: new ( "a[!0-9]b" ) . unwrap ( ) ;
1044
1040
for i in 0 ..10 {
1045
- assert ! ( !pat. matches( format!( "a{}b" , i) . as_slice ( ) ) ) ;
1041
+ assert ! ( !pat. matches( & format!( "a{}b" , i) ) ) ;
1046
1042
}
1047
1043
assert ! ( pat. matches( "a_b" ) ) ;
1048
1044
1049
1045
let pats = [ "[a-z123]" , "[1a-z23]" , "[123a-z]" ] ;
1050
1046
for & p in pats. iter ( ) {
1051
1047
let pat = Pattern :: new ( p) . unwrap ( ) ;
1052
1048
for c in "abcdefghijklmnopqrstuvwxyz" . chars ( ) {
1053
- assert ! ( pat. matches( c. to_string( ) . as_slice ( ) ) ) ;
1049
+ assert ! ( pat. matches( & c. to_string( ) ) ) ;
1054
1050
}
1055
1051
for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" . chars ( ) {
1056
1052
let options = MatchOptions { case_sensitive : false , .. MatchOptions :: new ( ) } ;
1057
- assert ! ( pat. matches_with( c. to_string( ) . as_slice ( ) , & options) ) ;
1053
+ assert ! ( pat. matches_with( & c. to_string( ) , & options) ) ;
1058
1054
}
1059
1055
assert ! ( pat. matches( "1" ) ) ;
1060
1056
assert ! ( pat. matches( "2" ) ) ;
@@ -1101,7 +1097,7 @@ mod test {
1101
1097
fn test_pattern_escape ( ) {
1102
1098
let s = "_[_]_?_*_!_" ;
1103
1099
assert_eq ! ( Pattern :: escape( s) , "_[[]_[]]_[?]_[*]_!_" . to_string( ) ) ;
1104
- assert ! ( Pattern :: new( Pattern :: escape( s) . as_slice ( ) ) . unwrap( ) . matches( s) ) ;
1100
+ assert ! ( Pattern :: new( & Pattern :: escape( s) ) . unwrap( ) . matches( s) ) ;
1105
1101
}
1106
1102
1107
1103
#[ test]
0 commit comments