1010
1111use ast;
1212use parse:: { ParseSess , PResult , filemap_to_tts} ;
13- use parse:: new_parser_from_source_str;
13+ use parse:: { lexer , new_parser_from_source_str} ;
1414use parse:: parser:: Parser ;
1515use parse:: token;
1616use ptr:: P ;
@@ -97,8 +97,8 @@ pub fn matches_codepattern(a : &str, b : &str) -> bool {
9797 let ( a, b) = match ( a_iter. peek ( ) , b_iter. peek ( ) ) {
9898 ( None , None ) => return true ,
9999 ( None , _) => return false ,
100- ( Some ( a) , None ) => {
101- if a . is_whitespace ( ) {
100+ ( Some ( & a) , None ) => {
101+ if is_pattern_whitespace ( a ) {
102102 break // trailing whitespace check is out of loop for borrowck
103103 } else {
104104 return false
@@ -107,11 +107,11 @@ pub fn matches_codepattern(a : &str, b : &str) -> bool {
107107 ( Some ( & a) , Some ( & b) ) => ( a, b)
108108 } ;
109109
110- if a . is_whitespace ( ) && b . is_whitespace ( ) {
110+ if is_pattern_whitespace ( a ) && is_pattern_whitespace ( b ) {
111111 // skip whitespace for a and b
112112 scan_for_non_ws_or_end ( & mut a_iter) ;
113113 scan_for_non_ws_or_end ( & mut b_iter) ;
114- } else if a . is_whitespace ( ) {
114+ } else if is_pattern_whitespace ( a ) {
115115 // skip whitespace for a
116116 scan_for_non_ws_or_end ( & mut a_iter) ;
117117 } else if a == b {
@@ -123,23 +123,18 @@ pub fn matches_codepattern(a : &str, b : &str) -> bool {
123123 }
124124
125125 // check if a has *only* trailing whitespace
126- a_iter. all ( |c| c . is_whitespace ( ) )
126+ a_iter. all ( is_pattern_whitespace )
127127}
128128
129129/// Advances the given peekable `Iterator` until it reaches a non-whitespace character
130130fn scan_for_non_ws_or_end < I : Iterator < Item = char > > ( iter : & mut Peekable < I > ) {
131- loop {
132- match iter. peek ( ) {
133- Some ( c) if c. is_whitespace ( ) => { } // fall through; borrowck
134- _ => return
135- }
136-
131+ while lexer:: is_pattern_whitespace ( iter. peek ( ) . cloned ( ) ) {
137132 iter. next ( ) ;
138133 }
139134}
140135
141- pub fn is_whitespace ( c : char ) -> bool {
142- c . is_whitespace ( )
136+ pub fn is_pattern_whitespace ( c : char ) -> bool {
137+ lexer :: is_pattern_whitespace ( Some ( c ) )
143138}
144139
145140#[ cfg( test) ]
@@ -162,14 +157,18 @@ mod tests {
162157 }
163158
164159 #[ test]
165- fn more_whitespace ( ) {
160+ fn pattern_whitespace ( ) {
166161 assert_eq ! ( matches_codepattern( "" , "\x0C " ) , false ) ;
167- assert_eq ! ( matches_codepattern( "a b" , "a\u{2002} b" ) , true ) ;
168162 assert_eq ! ( matches_codepattern( "a b " , "a \u{0085} \n \t \r b" ) , true ) ;
169163 assert_eq ! ( matches_codepattern( "a b" , "a \u{0085} \n \t \r b " ) , false ) ;
170- assert_eq ! ( matches_codepattern( "a b" , "a\u{2002} b" ) , true ) ;
171- assert_eq ! ( matches_codepattern( "ab" , "a\u{2003} b" ) , false ) ;
172- assert_eq ! ( matches_codepattern( "a \u{3000} b" , "ab" ) , true ) ;
173- assert_eq ! ( matches_codepattern( "\u{205F} a b" , "ab" ) , true ) ;
164+ }
165+
166+ #[ test]
167+ fn non_pattern_whitespace ( ) {
168+ // These have the property 'White_Space' but not 'Pattern_White_Space'
169+ assert_eq ! ( matches_codepattern( "a b" , "a\u{2002} b" ) , false ) ;
170+ assert_eq ! ( matches_codepattern( "a b" , "a\u{2002} b" ) , false ) ;
171+ assert_eq ! ( matches_codepattern( "\u{205F} a b" , "ab" ) , false ) ;
172+ assert_eq ! ( matches_codepattern( "a \u{3000} b" , "ab" ) , false ) ;
174173 }
175174}
0 commit comments