diff --git a/Cargo.lock b/Cargo.lock index f549aacb68..b05d7b93eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2496,6 +2496,7 @@ dependencies = [ "unic-ucd-bidi", "unic-ucd-category", "unic-ucd-ident", + "unicode-bidi-mirroring", "unicode-casing", "unicode_names2", "uuid", @@ -3147,6 +3148,12 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicode-bidi-mirroring" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cb788ffebc92c5948d0e997106233eeb1d8b9512f93f41651f52b6c5f5af86" + [[package]] name = "unicode-casing" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 163289e8b2..fba5bc7849 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,6 +208,7 @@ unic-ucd-bidi = "0.9.0" unic-ucd-category = "0.9.0" unic-ucd-ident = "0.9.0" unicode_names2 = "1.3.0" +unicode-bidi-mirroring = "0.2" widestring = "1.1.0" windows-sys = "0.59.0" wasm-bindgen = "0.2.100" diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py index c9e0b234ef..29da4a25a3 100644 --- a/Lib/test/test_unicodedata.py +++ b/Lib/test/test_unicodedata.py @@ -179,8 +179,6 @@ def test_decomposition(self): self.assertRaises(TypeError, self.db.decomposition) self.assertRaises(TypeError, self.db.decomposition, 'xx') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_mirrored(self): self.assertEqual(self.db.mirrored('\uFFFE'), 0) self.assertEqual(self.db.mirrored('a'), 0) diff --git a/stdlib/Cargo.toml b/stdlib/Cargo.toml index f051ea7b2b..82c935b2cf 100644 --- a/stdlib/Cargo.toml +++ b/stdlib/Cargo.toml @@ -73,6 +73,7 @@ unic-ucd-category = { workspace = true } unic-ucd-age = { workspace = true } unic-ucd-ident = { workspace = true } ucd = "0.1.1" +unicode-bidi-mirroring = { workspace = true } # compression adler32 = "1.2.0" diff --git a/stdlib/src/unicodedata.rs b/stdlib/src/unicodedata.rs index 9af921d360..9024294f93 100644 --- a/stdlib/src/unicodedata.rs +++ b/stdlib/src/unicodedata.rs @@ -23,6 +23,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyRef { "bidirectional", "east_asian_width", "normalize", + "mirrored", ] .into_iter() { @@ -72,6 +73,7 @@ mod unicodedata { use unic_ucd_age::{Age, UNICODE_VERSION, UnicodeVersion}; use unic_ucd_bidi::BidiClass; use unic_ucd_category::GeneralCategory; + use unicode_bidi_mirroring::is_mirroring; #[pyattr] #[pyclass(name = "UCD")] @@ -193,6 +195,21 @@ mod unicodedata { Ok(normalized_text) } + #[pymethod] + fn mirrored(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult { + match self.extract_char(character, vm)? { + Some(c) => { + if let Some(ch) = c.to_char() { + // Check if the character is mirrored in bidirectional text using Unicode standard + Ok(if is_mirroring(ch) { 1 } else { 0 }) + } else { + Ok(0) + } + } + None => Ok(0), + } + } + #[pygetset] fn unidata_version(&self) -> String { self.unic_version.to_string() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy