pub fn html_entities(str_input: &str) -> String {
str_input.replace('<', "<").replace('>', ">")
}
pub fn normalize(str_input: &str) -> String {
html_entities(&str_input.replace('\t', " "))
}
use unicode_segmentation::UnicodeSegmentation;
pub fn wrap_text(line: &str, column_width: usize) -> String {
if column_width == 0 {
return line.to_string();
}
let graphemes: Vec<&str> = line.graphemes(true).collect();
if graphemes.len() <= column_width {
return line.to_string();
}
let mut result = String::new();
for (i, &g) in graphemes.iter().enumerate() {
if i > 0 && i % column_width == 0 {
result.push_str("<br/>");
}
result.push_str(g);
}
result
}
pub fn wrap_text_list(list: &[String], column_width: usize) -> Vec<String> {
list.iter().map(|s| wrap_text(s, column_width)).collect()
}
pub struct StringUtils;
impl StringUtils {
pub fn html_entities(str_input: &str) -> String {
html_entities(str_input)
}
pub fn normalize(str_input: &str) -> String {
normalize(str_input)
}
pub fn wrap_text(line: &str, column_width: usize) -> String {
if column_width == 0 {
panic!("column width must be positive");
}
wrap_text(line, column_width)
}
pub fn wrap_text_list(list: &[String], column_width: usize) -> Vec<String> {
wrap_text_list(list, column_width)
}
}