diff options
Diffstat (limited to 'crates/shirabe-external-packages/src/composer/pcre/pcre_exception.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/composer/pcre/pcre_exception.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/shirabe-external-packages/src/composer/pcre/pcre_exception.rs b/crates/shirabe-external-packages/src/composer/pcre/pcre_exception.rs new file mode 100644 index 0000000..4ebe2c3 --- /dev/null +++ b/crates/shirabe-external-packages/src/composer/pcre/pcre_exception.rs @@ -0,0 +1,36 @@ +//! ref: composer/vendor/composer/pcre/src/PcreException.php + +use super::preg::{preg_last_error, preg_last_error_msg}; + +#[derive(Debug)] +pub struct PcreException(pub shirabe_php_shim::RuntimeException); + +impl PcreException { + pub fn from_function(function: &str, pattern: &str) -> PcreException { + let code = preg_last_error(); + + PcreException(shirabe_php_shim::RuntimeException { + message: format!( + "{}(): failed executing \"{}\": {}", + function, + pattern, + Self::pcre_last_error_message(code) + ), + code, + }) + } + + // Modern PHP always provides preg_last_error_msg(), so the legacy fallbacks + // that scanned the pcre constants are not reproduced. + fn pcre_last_error_message(_code: i64) -> String { + preg_last_error_msg() + } +} + +impl std::fmt::Display for PcreException { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl std::error::Error for PcreException {} |
