aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/string/byte_string.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/string/byte_string.rs')
-rw-r--r--crates/shirabe-external-packages/src/symfony/string/byte_string.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/string/byte_string.rs b/crates/shirabe-external-packages/src/symfony/string/byte_string.rs
index ab17c1e..cd8eae8 100644
--- a/crates/shirabe-external-packages/src/symfony/string/byte_string.rs
+++ b/crates/shirabe-external-packages/src/symfony/string/byte_string.rs
@@ -8,11 +8,25 @@ pub struct ByteString {
}
impl ByteString {
- pub fn new(_string: &str) -> Self {
- todo!()
+ pub fn new(string: &str) -> Self {
+ Self {
+ string: string.to_string(),
+ }
}
- pub fn to_code_point_string(&self, _encoding: &str) -> CodePointString {
+ pub fn to_code_point_string(&self, from_encoding: &str) -> CodePointString {
+ // The source `string` is always valid UTF-8 (Rust `String`/`&str` guarantee). PHP takes the
+ // early-return branch whenever `preg_match('//u', ...)` holds for a UTF-8/null encoding, so
+ // the result mirrors the input bytes verbatim. The `mb_detect_encoding`/`iconv` conversion
+ // path only applies to genuinely non-UTF-8 byte strings, which cannot occur here.
+ if matches!(from_encoding, "" | "utf8" | "utf-8" | "UTF8" | "UTF-8") {
+ return CodePointString {
+ string: self.string.clone(),
+ };
+ }
+
+ // TODO(phase-d): non-UTF-8 source encodings would require mb_convert_encoding/iconv-style
+ // decoding, which is unreachable for the UTF-8-only inputs Shirabe currently produces.
todo!()
}
}