rust_web_server/ext/string_ext/
mod.rs

1use crate::symbol::SYMBOL;
2
3pub struct StringExt;
4
5impl StringExt {
6    pub fn truncate_new_line_carriage_return(str: &str) -> String {
7        str.replace("\r", "").replace("\n", "")
8    }
9
10    pub fn filter_ascii_control_characters(str: &str) -> String {
11        str.replace(|x : char | x.is_ascii_control(), SYMBOL.empty_string).trim().to_string()
12    }
13
14    pub fn float_number_with_precision(number: f64, number_of_digits: u8) -> String {
15        let formatted = format!("{0:.1$}", number, number_of_digits as usize);
16        formatted.to_string()
17    }
18}