aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-14 11:24:36 +0900
committernsfisis <nsfisis@gmail.com>2026-06-14 11:28:19 +0900
commit716f44031a39c5e43fb441ecc470db76efc23dd4 (patch)
treee6f4a31e4bf55a0a8efb06d9dd4844c567e7390f /crates/shirabe-external-packages
parentef9118c788c1cbb22ca7721b6a9e40c2bf2fe243 (diff)
downloadphp-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.gz
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.zst
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.zip
refactor(pcre): drop Result from Preg method return types
The Preg methods panic on PCRE failure (per the file header rationale), so their anyhow::Result wrappers never carried an Err. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages')
-rw-r--r--crates/shirabe-external-packages/src/composer/pcre/preg.rs104
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/table.rs3
5 files changed, 51 insertions, 68 deletions
diff --git a/crates/shirabe-external-packages/src/composer/pcre/preg.rs b/crates/shirabe-external-packages/src/composer/pcre/preg.rs
index 14be7a2..2f8c46b 100644
--- a/crates/shirabe-external-packages/src/composer/pcre/preg.rs
+++ b/crates/shirabe-external-packages/src/composer/pcre/preg.rs
@@ -11,14 +11,14 @@
use indexmap::IndexMap;
-pub const PREG_PATTERN_ORDER: i64 = 1;
-pub const PREG_SET_ORDER: i64 = 2;
-pub const PREG_OFFSET_CAPTURE: i64 = 256;
-pub const PREG_UNMATCHED_AS_NULL: i64 = 512;
-pub const PREG_SPLIT_NO_EMPTY: i64 = 1;
-pub const PREG_SPLIT_DELIM_CAPTURE: i64 = 2;
-pub const PREG_SPLIT_OFFSET_CAPTURE: i64 = 4;
-pub const PREG_GREP_INVERT: i64 = 1;
+const PREG_PATTERN_ORDER: i64 = 1;
+const PREG_SET_ORDER: i64 = 2;
+const PREG_OFFSET_CAPTURE: i64 = 256;
+const PREG_UNMATCHED_AS_NULL: i64 = 512;
+const PREG_SPLIT_NO_EMPTY: i64 = 1;
+const PREG_SPLIT_DELIM_CAPTURE: i64 = 2;
+const PREG_SPLIT_OFFSET_CAPTURE: i64 = 4;
+const PREG_GREP_INVERT: i64 = 1;
#[derive(Debug)]
pub struct Preg;
@@ -28,7 +28,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, String>>,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::match5(pattern, subject, matches, 0, 0)
}
@@ -38,7 +38,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, String>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::check_offset_capture(flags, "matchWithOffsets");
let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new();
@@ -55,10 +55,10 @@ impl Preg {
*out = drop_null_matches(internal);
}
- Ok(result == 1)
+ result == 1
}
- pub fn match_all(pattern: &str, subject: &str) -> anyhow::Result<usize> {
+ pub fn match_all(pattern: &str, subject: &str) -> usize {
Self::match_all5(pattern, subject, None, 0, 0)
}
@@ -66,7 +66,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, Vec<String>>>,
- ) -> anyhow::Result<usize> {
+ ) -> usize {
Self::match_all5(pattern, subject, matches, 0, 0)
}
@@ -76,7 +76,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, Vec<String>>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<usize> {
+ ) -> usize {
Self::check_offset_capture(flags, "matchAllWithOffsets");
Self::check_set_order(flags);
@@ -94,7 +94,7 @@ impl Preg {
*out = null_to_empty_match_all(internal);
}
- Ok(result as usize)
+ result as usize
}
pub fn match_all_with_offsets5(
@@ -103,7 +103,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, Vec<(String, usize)>>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<usize> {
+ ) -> usize {
Self::check_set_order(flags);
let mut internal: IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = IndexMap::new();
@@ -120,19 +120,14 @@ impl Preg {
*out = null_to_empty_offset_match_all(internal);
}
- Ok(result as usize)
+ result as usize
}
- pub fn replace(pattern: &str, replacement: &str, subject: &str) -> anyhow::Result<String> {
+ pub fn replace(pattern: &str, replacement: &str, subject: &str) -> String {
Self::replace_impl(pattern, replacement, subject, -1, None)
}
- pub fn replace4(
- pattern: &str,
- replacement: &str,
- subject: &str,
- limit: i64,
- ) -> anyhow::Result<String> {
+ pub fn replace4(pattern: &str, replacement: &str, subject: &str, limit: i64) -> String {
Self::replace_impl(pattern, replacement, subject, limit, None)
}
@@ -142,7 +137,7 @@ impl Preg {
subject: &str,
limit: i64,
count: &mut usize,
- ) -> anyhow::Result<String> {
+ ) -> String {
Self::replace_impl(pattern, replacement, subject, limit, Some(count))
}
@@ -152,19 +147,18 @@ impl Preg {
subject: &str,
limit: i64,
count: Option<&mut usize>,
- ) -> anyhow::Result<String> {
+ ) -> String {
// `$subject` is statically a string here, so the is_scalar/is_array
// guards (ARRAY_MSG / INVALID_TYPE_MSG) of the PHP original are
// unreachable and not reproduced.
- Ok(preg_replace(pattern, replacement, subject, limit, count)
- .unwrap_or_else(|| invalid_regex()))
+ preg_replace(pattern, replacement, subject, limit, count).unwrap_or_else(|| invalid_regex())
}
pub fn replace_callback<F: FnMut(&IndexMap<CaptureKey, String>) -> String>(
pattern: &str,
replacement: F,
subject: &str,
- ) -> anyhow::Result<String> {
+ ) -> String {
Self::replace_callback6(pattern, replacement, subject, -1, None, 0)
}
@@ -175,44 +169,37 @@ impl Preg {
limit: i64,
count: Option<&mut usize>,
flags: i64,
- ) -> anyhow::Result<String> {
+ ) -> String {
let adapter = |internal: &IndexMap<CaptureKey, Option<String>>| -> String {
replacement(&drop_null_matches_ref(internal))
};
- Ok(
- preg_replace_callback(pattern, adapter, subject, limit, count, flags)
- .unwrap_or_else(|| invalid_regex()),
- )
+ preg_replace_callback(pattern, adapter, subject, limit, count, flags)
+ .unwrap_or_else(|| invalid_regex())
}
- pub fn split(pattern: &str, subject: &str) -> anyhow::Result<Vec<String>> {
+ pub fn split(pattern: &str, subject: &str) -> Vec<String> {
Self::split4(pattern, subject, -1, 0)
}
- pub fn split4(
- pattern: &str,
- subject: &str,
- limit: i64,
- flags: i64,
- ) -> anyhow::Result<Vec<String>> {
+ pub fn split4(pattern: &str, subject: &str, limit: i64, flags: i64) -> Vec<String> {
assert!(
flags & PREG_SPLIT_OFFSET_CAPTURE == 0,
"PREG_SPLIT_OFFSET_CAPTURE is not supported as it changes the type of $matches, use splitWithOffsets() instead"
);
- Ok(preg_split(pattern, subject, limit, flags).unwrap_or_else(|| invalid_regex()))
+ preg_split(pattern, subject, limit, flags).unwrap_or_else(|| invalid_regex())
}
- pub fn grep(pattern: &str, array: &[&str]) -> anyhow::Result<Vec<String>> {
+ pub fn grep(pattern: &str, array: &[&str]) -> Vec<String> {
Self::grep3(pattern, array, 0)
}
- pub fn grep3(pattern: &str, array: &[&str], flags: i64) -> anyhow::Result<Vec<String>> {
- Ok(preg_grep(pattern, array, flags).unwrap_or_else(|| invalid_regex()))
+ pub fn grep3(pattern: &str, array: &[&str], flags: i64) -> Vec<String> {
+ preg_grep(pattern, array, flags).unwrap_or_else(|| invalid_regex())
}
- pub fn is_match(pattern: &str, subject: &str) -> anyhow::Result<bool> {
+ pub fn is_match(pattern: &str, subject: &str) -> bool {
Self::match5(pattern, subject, None, 0, 0)
}
@@ -220,7 +207,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, String>>,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::match5(pattern, subject, matches, 0, 0)
}
@@ -230,7 +217,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, String>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::match5(pattern, subject, matches, flags, offset)
}
@@ -238,7 +225,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: &mut IndexMap<String, String>,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new();
let result = preg_match(
pattern,
@@ -256,13 +243,10 @@ impl Preg {
}
}
- Ok(result == 1)
+ result == 1
}
- pub fn is_match_with_indexed_captures(
- pattern: &str,
- subject: &str,
- ) -> anyhow::Result<Option<Vec<String>>> {
+ pub fn is_match_with_indexed_captures(pattern: &str, subject: &str) -> Option<Vec<String>> {
// Classic preg_match semantics (no PREG_UNMATCHED_AS_NULL): trailing
// unmatched groups are truncated, interior unmatched groups become "".
let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new();
@@ -270,7 +254,7 @@ impl Preg {
.unwrap_or_else(|| invalid_regex());
if result == 0 {
- return Ok(None);
+ return None;
}
let max_index = internal
@@ -291,23 +275,23 @@ impl Preg {
captures.push(value);
}
- Ok(Some(captures))
+ Some(captures)
}
pub fn is_match_all3(
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, Vec<String>>>,
- ) -> anyhow::Result<bool> {
- Ok(Self::match_all5(pattern, subject, matches, 0, 0)? > 0)
+ ) -> bool {
+ Self::match_all5(pattern, subject, matches, 0, 0) > 0
}
pub fn is_match_all_with_offsets3(
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, Vec<(String, usize)>>>,
- ) -> anyhow::Result<bool> {
- Ok(Self::match_all_with_offsets5(pattern, subject, matches, 0, 0)? > 0)
+ ) -> bool {
+ Self::match_all_with_offsets5(pattern, subject, matches, 0, 0) > 0
}
fn check_offset_capture(flags: i64, use_function_name: &str) {
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
index 8561a69..f89d48e 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
@@ -176,7 +176,7 @@ impl JsonDescriptor {
"/\\s*[\\r\\n]\\s*/",
" ",
argument.get_description(),
- )?),
+ )),
);
data.insert(
"default".to_string(),
@@ -237,7 +237,7 @@ impl JsonDescriptor {
"/\\s*[\\r\\n]\\s*/",
" ",
option.get_description(),
- )?),
+ )),
);
data.insert(
"default".to_string(),
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
index aa4c0e7..93928e7 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
@@ -55,7 +55,7 @@ impl MarkdownDescriptor {
if !argument.get_description().is_empty() {
format!(
"{}\n\n",
- Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", argument.get_description())?
+ Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", argument.get_description())
)
} else {
String::new()
@@ -93,7 +93,7 @@ impl MarkdownDescriptor {
if !option.get_description().is_empty() {
format!(
"{}\n\n",
- Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", option.get_description())?
+ Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", option.get_description())
)
} else {
String::new()
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
index 221a341..d330447 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
@@ -70,7 +70,7 @@ impl TextDescriptor {
shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
),
argument.get_description(),
- )?),
+ )),
PhpMixed::String(default),
),
&options,
@@ -148,7 +148,7 @@ impl TextDescriptor {
shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
),
option.get_description(),
- )?),
+ )),
PhpMixed::String(default),
PhpMixed::String(if option.is_array() {
"<comment> (multiple values allowed)</comment>".to_string()
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
index f3bdcb0..71d6c78 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
@@ -677,8 +677,7 @@ impl Table {
let is_not_styled_by_tag = !Preg::is_match(
"/^<(\\w+|(\\w+=[\\w,]+;?)*)>.+<\\/(\\w+|(\\w+=\\w+;?)*)?>$/",
&cell_str,
- )
- .unwrap();
+ );
if is_not_styled_by_tag {
let cell_style = Self::cell_get_style(&cell).unwrap();
match cell_style.get_cell_format() {