(s: &str, ascii_only: bool)
| 659 | } |
| 660 | |
| 661 | fn encode_string(s: &str, ascii_only: bool) -> String { |
| 662 | flame_guard!("_json::encode_string"); |
| 663 | let mut buf = Vec::<u8>::with_capacity(s.len() + 2); |
| 664 | machinery::write_json_string(s, ascii_only, &mut buf) |
| 665 | // SAFETY: writing to a vec can't fail |
| 666 | .unwrap_or_else(|_| unsafe { core::hint::unreachable_unchecked() }); |
| 667 | // SAFETY: we only output valid utf8 from write_json_string |
| 668 | unsafe { String::from_utf8_unchecked(buf) } |
| 669 | } |
| 670 | |
| 671 | #[pyfunction] |
| 672 | fn encode_basestring(s: PyUtf8StrRef) -> String { |
no test coverage detected