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

Method escaped_char_len

crates/literal/src/escape.rs:200–215  ·  view source on GitHub ↗
(ch: CodePoint)

Source from the content-addressed store, hash-verified

198 }
199
200 fn escaped_char_len(ch: CodePoint) -> usize {
201 // surrogates are \uHHHH
202 let Some(ch) = ch.to_char() else { return 6 };
203 match ch {
204 '\\' | '\t' | '\r' | '\n' => 2,
205 ch if ch < ' ' || ch as u32 == 0x7f => 4, // \xHH
206 ch if ch.is_ascii() => 1,
207 ch if crate::char::is_printable(ch) => {
208 // max = std::cmp::max(ch, max);
209 ch.len_utf8()
210 }
211 ch if (ch as u32) < 0x100 => 4, // \xHH
212 ch if (ch as u32) < 0x10000 => 6, // \uHHHH
213 _ => 10, // \uHHHHHHHH
214 }
215 }
216
217 fn write_char(
218 ch: CodePoint,

Callers

nothing calls this directly

Calls 3

is_printableFunction · 0.85
to_charMethod · 0.45
is_asciiMethod · 0.45

Tested by

no test coverage detected