television_utils::strings

Function preprocess_line

Source
pub fn preprocess_line(line: &str) -> (String, Vec<i16>)
Expand description

Preprocesses a line of text for display.

This function trims the line, replaces non-printable characters, and truncates the line if it is too long.

§Examples

use television_utils::strings::preprocess_line;

let line = "Hello, World!";
let (processed, offsets) = preprocess_line(line);
assert_eq!(processed, "Hello, World!");
assert_eq!(offsets, vec![0,0,0,0,0,0,0,0,0,0,0,0,0]);

let line = "\x00World\x7F!";
let (processed, offsets) = preprocess_line(line);
assert_eq!(processed, "␀World␀!");
assert_eq!(offsets, vec![0,0,0,0,0,0,0,0]);

let line = "a".repeat(400);
let (processed, offsets) = preprocess_line(&line);
assert_eq!(processed.len(), 300);
assert_eq!(offsets, vec![0; 300]);