pub fn insert(s: &String, idx: usize, ins: &str) -> String {
        assert!(idx <= len(&s), "the index was larger than the target slice");
        let ins_len = len(&ins.to_string());
        let fin_len = len(&s) + ins_len;
        let mut r = String::with_capacity(fin_len);
        for i in 0..fin_len {
            if i < idx {
                r.push_str(&slice(&s, i..i + 1));
            } else if i < idx + ins_len {
                let i_ins = i - idx;
                r.push_str(&slice(&ins.to_string(), i_ins..i_ins + 1));
            } else {
                let a_ins = i - ins_len;
                r.push_str(&slice(&s, a_ins..a_ins + 1));
            }
        }
        r
    }
/*
    inserts str into string, preserving graphemes
    */
inserts str into string, preserving graphemes
inserts str into string preserving graphemes
pub fn insert(s: &String, idx: usize, ins: &str) -> String {
        assert!(idx <= len(&s), "the index was larger than the target slice");
        let ins_len = len(&ins.to_string());
        let fin_len = len(&s) + ins_len;
        let mut r = String::with_capacity(fin_len);
        for i in 0..fin_len {
            if i < idx {
                r.push_str(&slice(&s, i..i + 1));
            } else if i < idx + ins_len {
                let i_ins = i - idx;
                r.push_str(&slice(&ins.to_string(), i_ins..i_ins + 1));
            } else {
                let a_ins = i - ins_len;
                r.push_str(&slice(&s, a_ins..a_ins + 1));
            }
        }
        r
    }
pub fn insert ( s : & String , idx : usize , ins : & str ) -> String { assert ! ( idx len ( s ) " " ) ; let ins_len = len ( & ins . to_string ( ) ) ; let fin_len = len ( & s ) + ins_len ; let mut r = String :: with_capacity ( fin_len ) ; for i in 0 .. fin_len { if i < idx { r . push_str ( & slice ( & s , i .. i + 1 ) ) ; } else if i < idx + ins_len { let i_ins = i - idx ; r . push_str ( & slice ( & ins . to_string ( ) , i_ins .. i_ins + 1 ) ) ; } else { let a_ins = i - ins_len ; r . push_str ( & slice ( & s , a_ins .. a_ins + 1 ) ) ; } } r }
inserts str into string, preserving graphemes
inserts str into string preserving graphemes
s
&String
idx
usize
ins
&str
s
&String
idx
usize
ins
&str