(&self)
| 1353 | |
| 1354 | #[pymethod] |
| 1355 | pub fn isidentifier(&self) -> bool { |
| 1356 | let Some(s) = self.to_str() else { return false }; |
| 1357 | let mut chars = s.chars(); |
| 1358 | let is_identifier_start = chars.next().is_some_and(|c| c == '_' || is_xid_start(c)); |
| 1359 | // a string is not an identifier if it has whitespace or starts with a number |
| 1360 | is_identifier_start && chars.all(is_xid_continue) |
| 1361 | } |
| 1362 | |
| 1363 | // https://docs.python.org/3/library/stdtypes.html#str.translate |
| 1364 | #[pymethod] |