diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-19 23:54:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 00:01:37 +0900 |
| commit | e5fcde172b38d9a71292d0b4dd7f5d347da2e748 (patch) | |
| tree | c1091a1d94efb1c3ac1cda7c59a18ce53d74313b /crates/shirabe-external-packages/src/symfony/string/unicode_string.rs | |
| parent | adfa7c6b295521a6f8fdf4084993a80a8030e49b (diff) | |
| download | php-shirabe-e5fcde172b38d9a71292d0b4dd7f5d347da2e748.tar.gz php-shirabe-e5fcde172b38d9a71292d0b4dd7f5d347da2e748.tar.zst php-shirabe-e5fcde172b38d9a71292d0b4dd7f5d347da2e748.zip | |
feat(command): implement --help output
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/string/unicode_string.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/string/unicode_string.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/string/unicode_string.rs b/crates/shirabe-external-packages/src/symfony/string/unicode_string.rs index 396dcf3..8917f20 100644 --- a/crates/shirabe-external-packages/src/symfony/string/unicode_string.rs +++ b/crates/shirabe-external-packages/src/symfony/string/unicode_string.rs @@ -6,12 +6,32 @@ pub struct UnicodeString { } impl UnicodeString { - pub fn new(_string: &str) -> Self { - todo!() + // TODO(phase-c): the real constructor runs `normalizer_normalize` (Unicode NFC normalization), + // which has no Rust std equivalent and would need a dedicated normalization implementation. + // Normalization is skipped here, which is only correct for already-NFC input such as ASCII. + pub fn new(string: &str) -> Self { + Self { + string: string.to_string(), + } } - pub fn width(&self, _ignore_unsupported_encoding: bool) -> i64 { - todo!() + // TODO(phase-c): ASCII-only provisional implementation. The faithful `width()` uses `wcswidth` + // with the Unicode width tables to treat wide characters as width 2 and skip zero-width / + // combining characters; here every character counts as width 1, correct only for ASCII. The + // ANSI/control-character stripping driven by `ignore_ansi_decoration` is likewise not handled. + pub fn width(&self, _ignore_ansi_decoration: bool) -> i64 { + let s = self.string.replace(['\x00', '\x05', '\x07'], ""); + let s = s.replace("\r\n", "\n").replace('\r', "\n"); + + let mut width: i64 = 0; + for line in s.split('\n') { + let line_width = line.chars().count() as i64; + if line_width > width { + width = line_width; + } + } + + width } pub fn length(&self) -> i64 { |
