/// Utility function to only display the first and last N characters of a long string. This function is aware of unicode
/// graphemes
Utility function to only display the first and last N characters of a long string. This function is aware of unicode
graphemes
Utility function to only display the first and last N characters of a long string . This function is aware of unicode graphemes
pub fn display_compressed_string(string: String, len_first: usize, len_last: usize) -> String {
    let graphemes = UnicodeSegmentation::graphemes(string.as_str(), true).collect::<Vec<&str>>();
    if len_first + len_last >= graphemes.len() {
        return string;
    }
    let mut result = "".to_string();
    for i in graphemes.iter().take(len_first) {
        result.push_str(i);
    }
    result.push_str("...");
    for i in graphemes.iter().skip(graphemes.len() - len_last) {
        result.push_str(i);
    }
    result
}
pub fn display_compressed_string ( string : String , len_first : usize , len_last : usize ) -> String { let graphemes = UnicodeSegmentation :: graphemes ( string . as_str ( ) , true ) . collect :: < Vec < & str > > ( ) ; if len_first + len_last >= graphemes . len ( ) { return string ; } let mut result = " " . to_string ( ) ; for i in graphemes . iter ( ) . take ( len_first ) { result . push_str ( i ) ; } result . push_str ( " " ) ; for i in graphemes . iter ( ) . skip ( graphemes . len ( ) - len_last ) { result . push_str ( i ) ; } result }
Utility function to only display the first and last N characters of a long string.
Utility function to only display the first and last N characters of a long string .
string
String
len_first
usize
len_last
usize