/** * Copy a range * @param r the range to copy * @return the duplicated range */ range *range_copy( range *r ) { range *r2 = range_create( r->name, r->html_name, r->start, r->len ); if ( r2 != NULL ) { annotation *a = r->annotations; r2->reloff = r->reloff; r2->rightmost = r->rightmost; while ( a != NULL ) { annotation *a_copy = annotation_clone( a ); range_add_annotation( r2, a_copy ); a = annotation_get_next( a ); } } else warning("range: failed to duplicate range\n"); return r2; }
/** * Convert a range to a node * @param d the dom we are associated with * @param r the range to convert * @return the finished node */ static node *dom_range_to_node( dom *d, range *r ) { char *html_name = range_html_name(r); node *n = node_create( range_name(r),range_html_name(r),range_start(r), range_len(r), (html_name==NULL)?0:html_is_empty(html_name), range_get_rightmost(r) ); if ( n != NULL ) { annotation *ann = range_get_annotations( r ); while ( ann != NULL ) { attribute *attr = annotation_to_attribute( ann, range_name(r), d->css_rules ); if ( attr != NULL ) node_add_attribute( n, attr ); ann = annotation_get_next( ann ); } } return n; }
/** * Dispose of a single range * @param r the range in question */ void range_dispose( range *r ) { if ( r->name != NULL ) { free( r->name ); r->name = NULL; } if ( r->html_name != NULL ) { free( r->html_name ); r->html_name = NULL; } annotation *a = r->annotations; while ( a != NULL ) { annotation *next = annotation_get_next( a ); annotation_dispose( a ); a = next; } free( r ); }