MCPcopy Index your code
hub / github.com/RustPython/RustPython / encode_string

Function encode_string

crates/stdlib/src/json.rs:661–669  ·  view source on GitHub ↗
(s: &str, ascii_only: bool)

Source from the content-addressed store, hash-verified

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 {

Callers 4

encode_basestringFunction · 0.70
encode_basestring_asciiFunction · 0.70
DER_cert_to_PEM_certFunction · 0.70
public_bytesMethod · 0.70

Calls 2

write_json_stringFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected