pub fn replace_non_printable(
input: &[u8],
config: &ReplaceNonPrintableConfig,
) -> (String, Vec<i16>)
Expand description
Replaces non-printable characters in the given byte slice with default printable characters.
The tab width is used to determine how many spaces to replace a tab character with. The default printable character for non-printable characters is the Unicode symbol for NULL.
The function returns a tuple containing the processed string and a vector of offsets introduced by the transformation.
ยงExamples
use television_utils::strings::{replace_non_printable, ReplaceNonPrintableConfig};
let input = b"Hello, World!";
let (output, offsets) = replace_non_printable(input, &ReplaceNonPrintableConfig::default());
assert_eq!(output, "Hello, World!");
assert_eq!(offsets, vec![0,0,0,0,0,0,0,0,0,0,0,0,0]);
let input = b"Hello,\tWorld!";
let (output, offsets) = replace_non_printable(input, &ReplaceNonPrintableConfig::default().tab_width(4));
assert_eq!(output, "Hello, World!");
assert_eq!(offsets, vec![0,0,0,0,0,0,0,3,3,3,3,3,3]);
let input = b"Hello,\nWorld!";
let (output, offsets) = replace_non_printable(input, &ReplaceNonPrintableConfig::default());
assert_eq!(output, "Hello,World!");
assert_eq!(offsets, vec![0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1]);