From 530d085d4f3e19f94ac3cf8f8ac3b17000214b2e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 01:57:02 +0900 Subject: refactor(pcre): inline Preg into its call sites and drop the crate Preg had shed everything it owned: after the last few rounds its methods were one-line forwards to the shim's preg_*(), differing only in a default argument or a wrapper the caller unwrapped anyway. The 460 call sites now name the shim function, and shirabe-pcre is gone from the workspace along with its LICENSE entry. The forwards expand as they read: isMatch becomes preg_match2(.., 0).is_some() (is_none() where PHP negates it), isMatch3 and match3 drop the .is_some(), matchAll counts through preg_match_all2(..).occurrence_count(), and replace4/replace5 spell out the limit and count arguments preg_replace2 takes. Callbacks are the one place the shapes differ: preg_replace_callback carries an error out of the callback, so the fourteen infallible closures wrap their result in Ok() and expect() it back. Config::process() is the fifteenth, and it drops the `error` cell it captured to smuggle a failure past a closure that could only return a String. The `?` in the closure now carries it, which is what the PHP does -- a throw from the callback leaves preg_replace_callback at the failing match rather than running the remaining replacements and reporting the last error. The module doc that explained why composer/pcre's exceptions and *StrictGroups() variants have no counterpart moves to the shim's preg module, where the functions it describes live. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/util/remote_filesystem.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'crates/shirabe/src/util/remote_filesystem.rs') diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index e55e5200..7af5473a 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -13,14 +13,14 @@ use crate::util::Url; use crate::util::http::ProxyManager; use crate::util::http::Response; use indexmap::IndexMap; -use shirabe_pcre::Preg; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS, array_replace_recursive, base64_encode, explode, extension_loaded, file_get_contents, file_get_contents5, file_put_contents, filter_var_boolean, gethostbyname, http_clear_last_response_headers, http_get_last_response_headers, ini_get, json_decode_assoc, - parse_url, php_regex, preg_quote, strpos, strtolower, strtr, substr, trim, zlib_decode, + parse_url, php_regex, preg_match2, preg_quote, preg_replace, strpos, strtolower, strtr, substr, + trim, zlib_decode, }; /// Result of `RemoteFilesystem::get` — string content, `true` (for copy), or `false`. @@ -148,7 +148,7 @@ impl RemoteFilesystem { pub fn find_status_code(headers: &[String]) -> Option { let mut value: Option = None; for header in headers { - if let Some(m) = Preg::is_match3(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header) { + if let Some(m) = preg_match2(php_regex!("{^HTTP/\\S+ (\\d+)}i"), header, 0) { value = m.get(1).and_then(|s| s.parse().ok()).or(Some(0)); } } @@ -159,7 +159,7 @@ impl RemoteFilesystem { pub fn find_status_message(&self, headers: &[String]) -> Option { let mut value: Option = None; for header in headers { - if Preg::is_match(php_regex!("{^HTTP/\\S+ \\d+}i"), header) { + if preg_match2(php_regex!("{^HTTP/\\S+ \\d+}i"), header, 0).is_some() { value = Some(header.clone()); } } @@ -285,10 +285,13 @@ impl RemoteFilesystem { crate::io::DEBUG, ); - if (!Preg::is_match( + if (preg_match2( php_regex!("{^http://(repo\\.)?packagist\\.org/p/}"), &file_url, - ) || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none())) + 0, + ) + .is_none() + || (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none())) && !degraded_packagist { let _ = self.config.borrow_mut().prohibit_url_by_config( @@ -472,10 +475,12 @@ impl RemoteFilesystem { None, ) != ".zip") && content_type.is_some() - && Preg::is_match( + && preg_match2( php_regex!("{^text/html\\b}i"), content_type.as_deref().unwrap_or(""), - ); + 0, + ) + .is_some(); if bitbucket_login_match { result = None; if retry_auth_failure { @@ -941,7 +946,7 @@ impl RemoteFilesystem { .and_then(|parsed| parsed.host) .unwrap_or_default(); - target_url = Some(Preg::replace( + target_url = Some(preg_replace( format!( "{{^(.+(?://|@){}(?::\\d+)?)(?:[/\\?].*)?$}}", preg_quote(&url_host, None) @@ -950,7 +955,7 @@ impl RemoteFilesystem { &self.file_url, )); } else { - target_url = Some(Preg::replace( + target_url = Some(preg_replace( php_regex!("{^(.+/)[^/?]*(?:\\?.*)?$}"), &format!("\\1{}", location_header), &self.file_url, -- cgit v1.3.1-4-g156e