diff options
| -rw-r--r-- | crates/shirabe-class-map-generator/src/php_file_parser.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe-pcre/src/preg.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe/src/command/init_command.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/git_downloader.rs | 8 |
4 files changed, 14 insertions, 20 deletions
diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs index e6eeb028..b35988fb 100644 --- a/crates/shirabe-class-map-generator/src/php_file_parser.rs +++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs @@ -86,7 +86,7 @@ impl PhpFileParser { et = extra_types ); let mut matches: IndexMap<_, _> = IndexMap::new(); - Preg::match_all3(&pattern2, &contents, Some(&mut matches)); + Preg::match_all2(&pattern2, &contents, &mut matches); let mut classes = vec![]; let mut namespace = String::new(); diff --git a/crates/shirabe-pcre/src/preg.rs b/crates/shirabe-pcre/src/preg.rs index 10ed1d5b..55388a9f 100644 --- a/crates/shirabe-pcre/src/preg.rs +++ b/crates/shirabe-pcre/src/preg.rs @@ -57,22 +57,16 @@ impl Preg { } pub fn match_all(pattern: impl PregPattern, subject: &str) -> usize { - Self::match_all3(pattern, subject, None) + let mut dummy = IndexMap::new(); + preg_match_all2(pattern, subject, &mut dummy) } - pub fn match_all3( + pub fn match_all2( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, Vec<Option<String>>>>, + matches: &mut IndexMap<CaptureKey, Vec<Option<String>>>, ) -> usize { - let mut internal: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); - let result = preg_match_all2(pattern, subject, &mut internal); - - if let Some(out) = matches { - *out = internal; - } - - result + preg_match_all2(pattern, subject, matches) } fn match_all_with_offsets5( @@ -220,12 +214,12 @@ impl Preg { Some(captures) } - pub fn is_match_all3( + pub fn is_match_all( pattern: impl PregPattern, subject: &str, - matches: Option<&mut IndexMap<CaptureKey, Vec<Option<String>>>>, + matches: &mut IndexMap<CaptureKey, Vec<Option<String>>>, ) -> bool { - Self::match_all3(pattern, subject, matches) > 0 + Self::match_all2(pattern, subject, matches) > 0 } pub fn is_match_all_with_offsets3( diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index 1ca3e428..af3d16e2 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -176,7 +176,7 @@ impl InitCommand { { *self.git_config.borrow_mut() = Some(IndexMap::new()); let mut m: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); - if Preg::is_match_all3(php_regex!(r"{^([^=]+)=(.*)$}m"), &output, Some(&mut m)) { + if Preg::is_match_all(php_regex!(r"{^([^=]+)=(.*)$}m"), &output, &mut m) { let keys: Vec<Option<String>> = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); let values: Vec<Option<String>> = diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index b34f7800..7aeea252 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -110,10 +110,10 @@ impl GitDownloader { .unwrap_or_default(); let mut branches_match: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); - if !Preg::is_match_all3( + if !Preg::is_match_all( format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)), &refs, - Some(&mut branches_match), + &mut branches_match, ) { // not on a branch, we are either on a not-modified tag or some sort of detached head, so skip this return Ok(None); @@ -138,13 +138,13 @@ impl GitDownloader { // try to find matching branch names in remote repos for candidate in &candidate_branches { let mut m: IndexMap<CaptureKey, Vec<Option<String>>> = IndexMap::new(); - if Preg::is_match_all3( + if Preg::is_match_all( format!( "{{^[a-f0-9]+ refs/remotes/((?:[^/]+)/{})$}}mi", preg_quote(candidate, None) ), &refs, - Some(&mut m), + &mut m, ) { let matches: Vec<Option<String>> = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); |
