##// END OF EJS Templates
rustfilepatterns: shorter code for concatenating slices...
Valentin Gatien-Baron -
r43131:406bd21d default draft
parent child Browse files
Show More
@@ -159,26 +159,20 b' fn _build_single_regex('
159 if pattern[0] == b'^' {
159 if pattern[0] == b'^' {
160 return pattern.to_owned();
160 return pattern.to_owned();
161 }
161 }
162 let mut res = b".*".to_vec();
162 [b".*", pattern].concat()
163 res.extend(pattern);
164 res
165 }
163 }
166 PatternSyntax::Path | PatternSyntax::RelPath => {
164 PatternSyntax::Path | PatternSyntax::RelPath => {
167 if pattern == b"." {
165 if pattern == b"." {
168 return vec![];
166 return vec![];
169 }
167 }
170 let mut pattern = escape_pattern(pattern);
168 [escape_pattern(pattern).as_slice(), b"(?:/|$)"].concat()
171 pattern.extend(b"(?:/|$)");
172 pattern
173 }
169 }
174 PatternSyntax::RootFiles => {
170 PatternSyntax::RootFiles => {
175 let mut res = if pattern == b"." {
171 let mut res = if pattern == b"." {
176 vec![]
172 vec![]
177 } else {
173 } else {
178 // Pattern is a directory name.
174 // Pattern is a directory name.
179 let mut as_vec: Vec<u8> = escape_pattern(pattern);
175 [escape_pattern(pattern).as_slice(), b"/"].concat()
180 as_vec.push(b'/');
181 as_vec
182 };
176 };
183
177
184 // Anything after the pattern must be a non-directory.
178 // Anything after the pattern must be a non-directory.
@@ -186,24 +180,16 b' fn _build_single_regex('
186 res
180 res
187 }
181 }
188 PatternSyntax::RelGlob => {
182 PatternSyntax::RelGlob => {
189 let mut res: Vec<u8> = vec![];
190 let glob_re = glob_to_re(pattern);
183 let glob_re = glob_to_re(pattern);
191 if let Some(rest) = glob_re.drop_prefix(b"[^/]*") {
184 if let Some(rest) = glob_re.drop_prefix(b"[^/]*") {
192 res.extend(b".*");
185 [b".*", rest, globsuffix].concat()
193 res.extend(rest);
194 } else {
186 } else {
195 res.extend(b"(?:|.*/)");
187 [b"(?:|.*/)", glob_re.as_slice(), globsuffix].concat()
196 res.extend(glob_re);
197 }
188 }
198 res.extend(globsuffix.iter());
199 res
200 }
189 }
201 PatternSyntax::Glob
190 PatternSyntax::Glob
202 | PatternSyntax::RootGlob => {
191 | PatternSyntax::RootGlob => {
203 let mut res: Vec<u8> = vec![];
192 [glob_to_re(pattern).as_slice(), globsuffix].concat()
204 res.extend(glob_to_re(pattern));
205 res.extend(globsuffix.iter());
206 res
207 }
193 }
208 }
194 }
209 }
195 }
General Comments 0
You need to be logged in to leave comments. Login now