blob: cd8eae86f089de7921733b092ef1384cae7ebe48 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//! ref: composer/vendor/symfony/string/ByteString.php
use crate::symfony::string::code_point_string::CodePointString;
#[derive(Debug, Clone)]
pub struct ByteString {
pub(crate) string: String,
}
impl ByteString {
pub fn new(string: &str) -> Self {
Self {
string: string.to_string(),
}
}
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!()
}
}
|