diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-20 03:12:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 03:12:49 +0900 |
| commit | 324e4347d86563d1ab6068c0d4b6268c9c49e256 (patch) | |
| tree | 7b60732841fd287123eeacbd46d47b2e0be84f89 /crates | |
| parent | 25fa6c6b079b100f1c3970662d06d63bd741c1f0 (diff) | |
| download | php-shirabe-324e4347d86563d1ab6068c0d4b6268c9c49e256.tar.gz php-shirabe-324e4347d86563d1ab6068c0d4b6268c9c49e256.tar.zst php-shirabe-324e4347d86563d1ab6068c0d4b6268c9c49e256.zip | |
feat(platform): implement Runtime::parse_html_extension_info
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/src/platform/runtime.rs | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/crates/shirabe/src/platform/runtime.rs b/crates/shirabe/src/platform/runtime.rs index 2e04453..156eebb 100644 --- a/crates/shirabe/src/platform/runtime.rs +++ b/crates/shirabe/src/platform/runtime.rs @@ -1,7 +1,9 @@ //! ref: composer/src/Composer/Platform/Runtime.php use anyhow::Result; -use shirabe_php_shim::PhpMixed; +use indexmap::IndexMap; +use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; +use shirabe_php_shim::{PhpMixed, html_entity_decode, implode, strip_tags, trim}; #[derive(Debug)] pub struct Runtime; @@ -48,6 +50,50 @@ impl Runtime { } pub fn parse_html_extension_info(html: &str) -> String { - todo!() + let mut result: Vec<String> = vec![]; + + let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); + if Preg::match3( + r"~<h2>\s*<a[^>]*>([^<]+)</a>\s*</h2>~i", + html, + Some(&mut matches), + ) { + result.push(trim( + &html_entity_decode( + matches + .get(&CaptureKey::ByIndex(1)) + .map(|s| s.as_str()) + .unwrap_or(""), + ), + None, + )); + result.push(String::new()); + } + + let mut matches: IndexMap<CaptureKey, Vec<String>> = IndexMap::new(); + if Preg::match_all3( + r#"~<tr>\s*<td class="e">\s*(.*?)\s*</td>\s*<td class="v">\s*(.*?)\s*</td>\s*</tr>~is"#, + html, + Some(&mut matches), + ) > 0 + { + let group1 = matches + .get(&CaptureKey::ByIndex(1)) + .cloned() + .unwrap_or_default(); + let group2 = matches + .get(&CaptureKey::ByIndex(2)) + .cloned() + .unwrap_or_default(); + let count = std::cmp::min(group1.len(), group2.len()); + + for i in 0..count { + let key = trim(&html_entity_decode(&strip_tags(&group1[i])), None); + let value = trim(&html_entity_decode(&strip_tags(&group2[i])), None); + result.push(format!("{} => {}", key, value)); + } + } + + implode("\n", &result) } } |
