Method
digit
(
&self,
character: PyStrRef,
default: OptionalArg<PyObjectRef>,
vm: &VirtualMachine,
)
Source from the content-addressed store, hash-verified
| 254 | |
| 255 | #[pymethod] |
| 256 | fn digit( |
| 257 | &self, |
| 258 | character: PyStrRef, |
| 259 | default: OptionalArg<PyObjectRef>, |
| 260 | vm: &VirtualMachine, |
| 261 | ) -> PyResult { |
| 262 | let ch = self.extract_char(character, vm)?.and_then(|c| c.to_char()); |
| 263 | if let Some(ch) = ch |
| 264 | && matches!( |
| 265 | ch.numeric_type(), |
| 266 | Some(NumericType::Decimal) | Some(NumericType::Digit) |
| 267 | ) |
| 268 | && let Some(Number::Integer(n)) = ch.numeric_value() |
| 269 | { |
| 270 | return Ok(vm.ctx.new_int(n).into()); |
| 271 | } |
| 272 | default.ok_or_else(|| vm.new_value_error("not a digit")) |
| 273 | } |
| 274 | |
| 275 | #[pymethod] |
| 276 | fn decimal( |