MCPcopy Index your code
hub / github.com/endbasic/endbasic / remove_control_chars

Function remove_control_chars

std/src/console/mod.rs:423–442  ·  view source on GitHub ↗

Removes control characters from a string to make it suitable for printing.

(s: S)

Source from the content-addressed store, hash-verified

421
422/// Removes control characters from a string to make it suitable for printing.
423pub fn remove_control_chars<S: Into<String>>(s: S) -> String {
424 let s = s.into();
425
426 // Handle the expected common case first. We use this function to strip control characters
427 // before printing them to the console, and thus we expect such input strings to rarely include
428 // control characters.
429 if !has_control_chars(&s) {
430 return s;
431 }
432
433 let mut o = String::with_capacity(s.len());
434 for ch in s.chars() {
435 if ch.is_control() {
436 o.push(' ');
437 } else {
438 o.push(ch);
439 }
440 }
441 o
442}
443
444/// Gets the value of the environment variable `name` and interprets it as a `u16`. Returns
445/// `None` if the variable is not set or if its contents are invalid.

Callers 10

printMethod · 0.85
writeMethod · 0.85
printMethod · 0.85
writeMethod · 0.85
printMethod · 0.85
writeMethod · 0.85
printMethod · 0.85
writeMethod · 0.85
printMethod · 0.85
writeMethod · 0.85

Calls 4

has_control_charsFunction · 0.85
charsMethod · 0.80
pushMethod · 0.80
lenMethod · 0.45

Tested by 2

printMethod · 0.68
writeMethod · 0.68