diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-19 00:10:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-19 00:11:03 +0900 |
| commit | c839244d8d09f3036ebfee8eef7eb6b147e593ab (patch) | |
| tree | fe48c94f2c2e62468beef5ff1a8f3cff6adeef4f /crates/shirabe/src/json | |
| parent | 48839250146b217e2756ed3c0e624fd341b54d6c (diff) | |
| download | php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.tar.gz php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.tar.zst php-shirabe-c839244d8d09f3036ebfee8eef7eb6b147e593ab.zip | |
fix(compile): fix various compile errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/json')
| -rw-r--r-- | crates/shirabe/src/json/json_file.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/json/json_formatter.rs | 29 | ||||
| -rw-r--r-- | crates/shirabe/src/json/json_manipulator.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/json/json_validation_exception.rs | 4 |
4 files changed, 33 insertions, 13 deletions
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index c1fa495..d08e207 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -401,7 +401,11 @@ impl JsonFile { /// @param int $options json_encode options (defaults to JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) /// @param string $indent Indentation string /// @return string Encoded json - pub fn encode(data: &PhpMixed, options: i64, indent: &str) -> String { + pub fn encode(data: &PhpMixed, options: i64) -> String { + Self::encode_with_indent(data, options, Self::INDENT_DEFAULT) + } + + pub fn encode_with_indent(data: &PhpMixed, options: i64, indent: &str) -> String { let json = json_encode_ex(data, options); let json = match json { diff --git a/crates/shirabe/src/json/json_formatter.rs b/crates/shirabe/src/json/json_formatter.rs index 1696982..47680b1 100644 --- a/crates/shirabe/src/json/json_formatter.rs +++ b/crates/shirabe/src/json/json_formatter.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Json/JsonFormatter.php -use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::composer::pcre::preg::{CaptureKey, Preg}; use shirabe_php_shim::{PhpMixed, function_exists, mb_convert_encoding, pack}; pub struct JsonFormatter; @@ -44,27 +44,40 @@ impl JsonFormatter { if unescape_unicode && function_exists("mb_convert_encoding") { buffer = Preg::replace_callback( r"/(\\+)u([0-9a-f]{4})/i", - |matches: &[String]| -> String { - let l = matches[1].len(); + |matches: &indexmap::IndexMap<CaptureKey, String>| -> String { + let m0 = matches + .get(&CaptureKey::ByIndex(0)) + .cloned() + .unwrap_or_default(); + let m1 = matches + .get(&CaptureKey::ByIndex(1)) + .cloned() + .unwrap_or_default(); + let m2 = matches + .get(&CaptureKey::ByIndex(2)) + .cloned() + .unwrap_or_default(); + let l = m1.len(); if l % 2 != 0 { - let code = i64::from_str_radix(&matches[2], 16).unwrap_or(0); + let code = i64::from_str_radix(&m2, 16).unwrap_or(0); if code >= 0xD800 && code <= 0xDFFF { - return matches[0].clone(); + return m0; } return "\\".repeat(l - 1) + &mb_convert_encoding( - pack("H*", &[PhpMixed::String(matches[2].clone())]), + pack("H*", &[PhpMixed::String(m2)]), "UTF-8", "UCS-2BE", ); } - matches[0].clone() + m0 }, &buffer, - ); + ) + .unwrap_or(buffer); } result.push_str(&buffer); diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs index ebbfff9..b9c6a5c 100644 --- a/crates/shirabe/src/json/json_manipulator.rs +++ b/crates/shirabe/src/json/json_manipulator.rs @@ -128,8 +128,7 @@ impl JsonManipulator { JsonFile::encode( &PhpMixed::String(str_replace("\\/", "/", &existing_owned)), 0 - ) - .unwrap_or_default(), + ), m.get("separator").cloned().unwrap_or_default(), constraint_owned ) @@ -1024,7 +1023,7 @@ impl JsonManipulator { if now_empty { arr.insert( name_owned.clone(), - Box::new(PhpMixed::Object(ArrayObject::new())), + Box::new(PhpMixed::Object(ArrayObject::new(None))), ); } } @@ -1068,7 +1067,7 @@ impl JsonManipulator { if now_empty { arr.insert( name_capture.clone(), - Box::new(PhpMixed::Object(ArrayObject::new())), + Box::new(PhpMixed::Object(ArrayObject::new(None))), ); } } diff --git a/crates/shirabe/src/json/json_validation_exception.rs b/crates/shirabe/src/json/json_validation_exception.rs index 5f3cbbf..4549a0f 100644 --- a/crates/shirabe/src/json/json_validation_exception.rs +++ b/crates/shirabe/src/json/json_validation_exception.rs @@ -19,6 +19,10 @@ impl JsonValidationException { pub fn get_errors(&self) -> &Vec<String> { &self.errors } + + pub fn get_message(&self) -> &str { + &self.inner.message + } } impl std::fmt::Display for JsonValidationException { |
