Esempio n. 1
0
myhtml_collection_t * myhtml_get_nodes_by_tag_id(myhtml_tree_t* tree, myhtml_collection_t *collection, myhtml_tag_id_t tag_id, mystatus_t *status)
{
    if(collection == NULL) {
        collection = myhtml_collection_create(1024, NULL);
        
        if(collection == NULL)
            return NULL;
    }
    
    myhtml_tree_node_t *node = tree->node_html;
    
    while(node)
    {
        if(node->tag_id == tag_id)
        {
            if(myhtml_collection_check_size(collection, 1, 1024) == MyHTML_STATUS_OK) {
                collection->list[ collection->length ] = node;
                collection->length++;
            }
            else {
                if(status)
                    *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
                
                return collection;
            }
        }
        
        if(node->child)
            node = node->child;
        else {
            while(node != tree->node_html && node->next == NULL)
                node = node->parent;
            
            if(node == tree->node_html)
                break;
            
            node = node->next;
        }
    }
    
    if(myhtml_collection_check_size(collection, 1, 1024) == MyHTML_STATUS_OK) {
        collection->list[ collection->length ] = NULL;
    }
    else if(status) {
        *status = MyHTML_STATUS_ERROR_MEMORY_ALLOCATION;
    }
    
    return collection;
}
Esempio n. 2
0
myhtml_collection_t * myhtml_get_nodes_by_tag_id(myhtml_tree_t* tree, myhtml_collection_t *collection, myhtml_tag_id_t tag_id, myhtml_status_t *status)
{
    myhtml_tag_index_entry_t *index_tag = myhtml_tag_index_entry(tree->indexes->tags, tag_id);
    myhtml_tag_index_node_t *index_node = myhtml_tag_index_first(tree->indexes->tags, tag_id);
    
    if(index_tag->count == 0) {
        if(status)
            *status = MyHTML_STATUS_OK;
        
        return collection;
    }
    
    myhtml_status_t mystatus = MyHTML_STATUS_OK;
    size_t idx = 0;
    
    if(collection == NULL) {
        collection = myhtml_collection_create((index_tag->count + 128), &mystatus);
        
        collection->length += index_tag->count;
    }
    else {
        idx = collection->length;
        mystatus = myhtml_collection_check_size(collection, index_tag->count);
    }
    
    if(mystatus) {
        if(status)
            *status = mystatus;
        
        return collection;
    }
    
    while (index_node)
    {
        collection->list[idx] = index_node->node;
        idx++;
        
        index_node = index_node->next;
    }
    
    collection->list[idx] = NULL;
    
    if(status)
        *status = mystatus;
    
    return collection;
}
Esempio n. 3
0
myhtml_status_t myhtml_get_nodes_by_attribute_value_recursion_by_key(myhtml_tree_t *tree, myhtml_tree_node_t* node,
                                                                     myhtml_collection_t* collection,
                                                                     myhtml_attribute_value_find_f func_eq,
                                                                     const char* key, size_t key_len,
                                                                     const char* value, size_t value_len)
{
    while(node)
    {
        if(node->token && node->token->attr_first) {
            myhtml_tree_attr_t* attr = node->token->attr_first;
            
            while(attr) {
                myhtml_string_t* str_key = &attr->key;
                myhtml_string_t* str = &attr->value;
                
                if(str_key->length == key_len && myhtml_strncasecmp(str_key->data, key, key_len) == 0)
                {
                    if(func_eq(str, value, value_len)) {
                        collection->list[ collection->length ] = node;
                        
                        collection->length++;
                        if(collection->length >= collection->size) {
                            myhtml_status_t status = myhtml_collection_check_size(collection, 1024, 0);
                            
                            if(status)
                                return status;
                        }
                    }
                }
                
                attr = attr->next;
            }
        }
        
        if(node->child) {
            myhtml_status_t status = myhtml_get_nodes_by_attribute_value_recursion_by_key(tree, node->child, collection, func_eq,
                                                                                          key, key_len, value, value_len);
            
            if(status)
                return status;
        }
        
        node = node->next;
    }
    
    return MyHTML_STATUS_OK;
}
Esempio n. 4
0
mystatus_t myhtml_get_nodes_by_attribute_key_recursion(myhtml_tree_node_t* node, myhtml_collection_t* collection, const char* key, size_t key_len)
{
    while(node)
    {
        if(node->token && node->token->attr_first) {
            myhtml_tree_attr_t* attr = node->token->attr_first;
            
            while(attr) {
                mycore_string_t* str_key = &attr->key;
                
                if(str_key->length == key_len && mycore_strncasecmp(str_key->data, key, key_len) == 0) {
                    collection->list[ collection->length ] = node;
                    
                    collection->length++;
                    if(collection->length >= collection->size) {
                        mystatus_t status = myhtml_collection_check_size(collection, 1024, 0);
                        
                        if(status)
                            return status;
                    }
                }
                
                attr = attr->next;
            }
        }
        
        if(node->child) {
            mystatus_t status = myhtml_get_nodes_by_attribute_key_recursion(node->child, collection, key, key_len);
            
            if(status)
                return status;
        }
        
        node = node->next;
    }
    
    return MyHTML_STATUS_OK;
}
Esempio n. 5
0
mystatus_t myhtml_get_nodes_by_tag_id_in_scope_find_recursion(myhtml_tree_node_t *node, myhtml_collection_t *collection, myhtml_tag_id_t tag_id)
{
    while(node) {
        if(node->tag_id == tag_id) {
            collection->list[ collection->length ] = node;
            collection->length++;
            
            if(collection->length >= collection->size)
            {
                mystatus_t mystatus = myhtml_collection_check_size(collection, 1024, 0);
                
                if(mystatus != MyHTML_STATUS_OK)
                    return mystatus;
            }
        }
        
        if(node->child)
            myhtml_get_nodes_by_tag_id_in_scope_find_recursion(node->child, collection, tag_id);
        
        node = node->next;
    }
    
    return MyHTML_STATUS_OK;
}