MCPcopy Create free account
hub / github.com/davidblewett/rure-python / escape_unicode

Function escape_unicode

regex/regex-debug/src/main.rs:290–313  ·  view source on GitHub ↗
(bytes: &[u8])

Source from the content-addressed store, hash-verified

288}
289
290fn escape_unicode(bytes: &[u8]) -> String {
291 let show = match ::std::str::from_utf8(bytes) {
292 Ok(v) => v.to_string(),
293 Err(_) => escape_bytes(bytes),
294 };
295 let mut space_escaped = String::new();
296 for c in show.chars() {
297 if c.is_whitespace() {
298 let escaped = if c as u32 <= 0x7F {
299 escape_byte(c as u8)
300 } else {
301 if c as u32 <= 0xFFFF {
302 format!(r"\u{{{:04x}}}", c as u32)
303 } else {
304 format!(r"\U{{{:08x}}}", c as u32)
305 }
306 };
307 space_escaped.push_str(&escaped);
308 } else {
309 space_escaped.push(c);
310 }
311 }
312 space_escaped
313}
314
315fn escape_bytes(bytes: &[u8]) -> String {
316 let mut s = String::new();

Callers

nothing calls this directly

Calls 3

escape_bytesFunction · 0.70
escape_byteFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected