| 235 | |
| 236 | #[pymethod] |
| 237 | fn decomposition(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult<String> { |
| 238 | let ch = match self.extract_char(character, vm)?.and_then(|c| c.to_char()) { |
| 239 | Some(ch) => ch, |
| 240 | None => return Ok(String::new()), |
| 241 | }; |
| 242 | let chars: Vec<char> = ch.decomposition_map().collect(); |
| 243 | // If decomposition maps to just the character itself, there's no decomposition |
| 244 | if chars.len() == 1 && chars[0] == ch { |
| 245 | return Ok(String::new()); |
| 246 | } |
| 247 | let hex_parts = chars.iter().map(|c| format!("{:04X}", *c as u32)).join(" "); |
| 248 | let tag = match ch.decomposition_type() { |
| 249 | Some(DecompositionType::Canonical) | None => return Ok(hex_parts), |
| 250 | Some(dt) => decomposition_type_tag(dt), |
| 251 | }; |
| 252 | Ok(format!("<{tag}> {hex_parts}")) |
| 253 | } |
| 254 | |
| 255 | #[pymethod] |
| 256 | fn digit( |