From d7c686f6c488739fc9d061bb0f89d73e6445fade Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 14 Jun 2026 13:08:21 +0900 Subject: refactor(pcre): return bool from preg_match shim preg_match can only return 1 or 0 now that compile failure panics, so return bool and update all call sites accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/preg.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/shirabe-php-shim/src/preg.rs') diff --git a/crates/shirabe-php-shim/src/preg.rs b/crates/shirabe-php-shim/src/preg.rs index dc91fd6..510f6ba 100644 --- a/crates/shirabe-php-shim/src/preg.rs +++ b/crates/shirabe-php-shim/src/preg.rs @@ -40,9 +40,9 @@ pub fn preg_quote(str: &str, delimiter: Option) -> String { out } -// Returns 1 on match, 0 on no match; populates matches[0]=full match, matches[1..]=captures. +// Returns whether the pattern matched; populates matches[0]=full match, matches[1..]=captures. // Optional groups that did not participate in the match are stored as None. -pub fn preg_match(pattern: &str, subject: &str, matches: &mut Vec>) -> i64 { +pub fn preg_match(pattern: &str, subject: &str, matches: &mut Vec>) -> bool { let re = compile_php_pattern(pattern).unwrap_or_else(|e| panic!("invalid regex: {e}")); matches.clear(); match re.captures(subject) { @@ -50,9 +50,9 @@ pub fn preg_match(pattern: &str, subject: &str, matches: &mut Vec for g in 0..caps.len() { matches.push(caps.get(g).map(|m| m.as_str().to_string())); } - 1 + true } - None => 0, + None => false, } } -- cgit v1.3.1