Skip to content

ucd.is_mirrored #5816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions stdlib/src/unicodedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
"bidirectional",
"east_asian_width",
"normalize",
"mirrored",
]
.into_iter()
{
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -193,6 +195,21 @@ mod unicodedata {
Ok(normalized_text)
}

#[pymethod]
fn mirrored(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult<i32> {
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()
Expand Down
Loading