Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/filepatterns.rs @ 42869:62eabdf91f85
rustfilepatterns: refactor the pattern of removing a prefix from a &[u8]
Differential Revision: https://phab.mercurial-scm.org/D6766
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 26 Aug 2019 08:25:01 -0400 |
parents | ce6797ef6eab |
children | 72890d8f9860 |
comparison
equal
deleted
inserted
replaced
42868:96ddf83fc267 | 42869:62eabdf91f85 |
---|---|
58 input = rest; | 58 input = rest; |
59 | 59 |
60 match c { | 60 match c { |
61 b'*' => { | 61 b'*' => { |
62 for (source, repl) in GLOB_REPLACEMENTS { | 62 for (source, repl) in GLOB_REPLACEMENTS { |
63 if input.starts_with(source) { | 63 if let Some(rest) = input.drop_prefix(source) { |
64 input = &input[source.len()..]; | 64 input = rest; |
65 res.extend(*repl); | 65 res.extend(*repl); |
66 break; | 66 break; |
67 } | 67 } |
68 } | 68 } |
69 } | 69 } |
267 | 267 |
268 if line.is_empty() { | 268 if line.is_empty() { |
269 continue; | 269 continue; |
270 } | 270 } |
271 | 271 |
272 if line.starts_with(b"syntax:") { | 272 if let Some(syntax) = line.drop_prefix(b"syntax:") { |
273 let syntax = line[b"syntax:".len()..].trim(); | 273 let syntax = syntax.trim(); |
274 | 274 |
275 if let Some(rel_syntax) = SYNTAXES.get(syntax) { | 275 if let Some(rel_syntax) = SYNTAXES.get(syntax) { |
276 current_syntax = rel_syntax; | 276 current_syntax = rel_syntax; |
277 } else if warn { | 277 } else if warn { |
278 warnings.push((file_path.to_owned(), syntax.to_owned())); | 278 warnings.push((file_path.to_owned(), syntax.to_owned())); |
281 } | 281 } |
282 | 282 |
283 let mut line_syntax: &[u8] = ¤t_syntax; | 283 let mut line_syntax: &[u8] = ¤t_syntax; |
284 | 284 |
285 for (s, rels) in SYNTAXES.iter() { | 285 for (s, rels) in SYNTAXES.iter() { |
286 if line.starts_with(rels) { | 286 if let Some(rest) = line.drop_prefix(rels) { |
287 line_syntax = rels; | 287 line_syntax = rels; |
288 line = &line[rels.len()..]; | 288 line = rest; |
289 break; | 289 break; |
290 } else if line.starts_with(&[s, b":".as_ref()].concat()) { | 290 } |
291 if let Some(rest) = line.drop_prefix(&[s, &b":"[..]].concat()) { | |
291 line_syntax = rels; | 292 line_syntax = rels; |
292 line = &line[s.len() + 1..]; | 293 line = rest; |
293 break; | 294 break; |
294 } | 295 } |
295 } | 296 } |
296 | 297 |
297 inputs.push(( | 298 inputs.push(( |