void rope_insert(rope *r, size_t pos, const uint8_t *str) { assert(r); assert(str); #ifdef DEBUG _rope_check(r); #endif pos = MIN(pos, r->num_chars); rope_iter iter; // First we need to search for the node where we'll insert the string. rope_node *e = iter_at_char_pos(r, pos, &iter); rope_insert_at_iter(r, e, &iter, str); #ifdef DEBUG _rope_check(r); #endif }
// Insert the given utf8 string into the rope at the specified position. size_t rope_insert_at_wchar(rope *r, size_t wchar_pos, const uint8_t *str) { assert(r); assert(str); #ifdef DEBUG _rope_check(r); #endif wchar_pos = MIN(wchar_pos, rope_wchar_count(r)); rope_iter iter; // First we need to search for the node where we'll insert the string. rope_node *e = iter_at_wchar_pos(r, wchar_pos, &iter); size_t pos = iter.s[r->head.height - 1].skip_size; rope_insert_at_iter(r, e, &iter, str); #ifdef DEBUG _rope_check(r); #endif return pos; }