(&self, vm: &VirtualMachine)
| 490 | } |
| 491 | |
| 492 | pub(crate) fn ensure_valid_utf8(&self, vm: &VirtualMachine) -> PyResult<()> { |
| 493 | if self.is_utf8() { |
| 494 | Ok(()) |
| 495 | } else { |
| 496 | let start = self |
| 497 | .as_wtf8() |
| 498 | .code_points() |
| 499 | .position(|c| c.to_char().is_none()) |
| 500 | .unwrap(); |
| 501 | Err(vm.new_unicode_encode_error_real( |
| 502 | identifier!(vm, utf_8).to_owned(), |
| 503 | vm.ctx.new_str(self.data.clone()), |
| 504 | start, |
| 505 | start + 1, |
| 506 | vm.ctx.new_str("surrogates not allowed"), |
| 507 | )) |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | pub fn to_string_lossy(&self) -> Cow<'_, str> { |
| 512 | self.to_str() |
no test coverage detected