Exemple #1
0
int cmark_node_append_child(cmark_node *node, cmark_node *child) {
  cmark_node *old_last_child;
  
  if (!S_can_contain(node, child)) {
    return 0;
  }

  S_node_unlink(child);

  old_last_child = node->last_child;

  child->next = NULL;
  child->prev = old_last_child;
  child->parent = node;
  node->last_child = child;

  if (old_last_child) {
    old_last_child->next = child;
  } else {
    // Also set first_child if node previously had no children.
    node->first_child = child;
  }

  return 1;
}
Exemple #2
0
int cmark_node_insert_after(cmark_node *node, cmark_node *sibling) {
  cmark_node *old_next, *parent;
  
  if (node == NULL || sibling == NULL) {
    return 0;
  }

  if (!node->parent || !S_can_contain(node->parent, sibling)) {
    return 0;
  }

  S_node_unlink(sibling);

  old_next = node->next;

  // Insert 'sibling' between 'node' and 'old_next'.
  if (old_next) {
    old_next->prev = sibling;
  }
  sibling->next = old_next;
  sibling->prev = node;
  node->next = sibling;

  // Set new parent.
  parent = node->parent;
  sibling->parent = parent;

  // Adjust last_child of parent if inserted as last child.
  if (parent && !old_next) {
    parent->last_child = sibling;
  }

  return 1;
}
Exemple #3
0
int cmark_node_insert_before(cmark_node *node, cmark_node *sibling) {
  cmark_node *old_prev, *parent;
  
  if (node == NULL || sibling == NULL) {
    return 0;
  }

  if (!node->parent || !S_can_contain(node->parent, sibling)) {
    return 0;
  }

  S_node_unlink(sibling);

  old_prev = node->prev;

  // Insert 'sibling' between 'old_prev' and 'node'.
  if (old_prev) {
    old_prev->next = sibling;
  }
  sibling->prev = old_prev;
  sibling->next = node;
  node->prev = sibling;

  // Set new parent.
  parent = node->parent;
  sibling->parent = parent;

  // Adjust first_child of parent if inserted as first child.
  if (parent && !old_prev) {
    parent->first_child = sibling;
  }

  return 1;
}
Exemple #4
0
void cmark_node_unlink(cmark_node *node) {
  S_node_unlink(node);

  node->next = NULL;
  node->prev = NULL;
  node->parent = NULL;
}
Exemple #5
0
void
cmark_node_free(cmark_node *node)
{
	S_node_unlink(node);
	node->next = NULL;
	S_free_nodes(node);
}
Exemple #6
0
void
cmark_node_destroy(cmark_node *node) {
	S_node_unlink(node);
	node->next = NULL;
	cmark_free_nodes(node);
}