Ejemplo n.º 1
0
/**
 * This function looks for the given string in the tree whose root
 * is 'node'. 'position' is the current position in the string. If the
 * string is not in the tree or if it has no value, 0 is returned;
 * otherwise, the function returns 1 and the value associated to the
 * string is saved in the 'result' parameter.
 */
int get_string_number(const struct search_tree_node* node,const char* string,int position,int *result) {
if (node==NULL) {
    /* If we find a NULL node, it means that the tree does not
     * contain the string, so we return 0. */
    return 0;
}
if (string[position]==node->c && string[position+1]=='\0') {
    /* If we are on the node with the correct letter, and if we are
     * at the end of the string, and if the node is final, then we
     * store the associated value and we return 1; otherwise we return 0. */
    if (!node->is_final) return 0;
    (*result)=node->value;
    return 1;
}
if (string[position]==node->c) {
    /* If have the correct letter but we are not at the end of the string,
     * then we explore the next letter in the 'middle' tree. */
    return get_string_number(node->middle,string,position+1,result);
}
if (string[position]<node->c) {
    /* If the current node is tagged by a letter that is greater than
     * the current letter, we look for the good node in the 'left' tree, but
     * we do not modify the position in the string. */
    return get_string_number(node->left,string,position,result);
}
/* Finally, if the current node is tagged by a that is greater than
 * the current letter, we look for the good node in the 'right' tree, but
 * we do not modify the position in the string. */
return get_string_number(node->right,string,position,result);
}
Ejemplo n.º 2
0
/**
 * This function takes a sequence representing an HTML control character
 * name like "gt" and returns its unicode number, or -1 if not found.
 */
int get_control_character_number(const struct HTML_character_context* html_context,const char* sequence) {
int value;
if (get_string_number(html_context->control_characters,sequence,&value)) return value;
return -1;
}
Ejemplo n.º 3
0
/**
 * Returns 1 if there is a value associated to the given string in the given tree.
 * In that case, this value is saved in 'result'. 0 is returned if the string is
 * not in the tree or has no value. A fatal error will be raised if the string
 * is NULL or empty.
 */
int get_string_number(const struct search_tree_node* root,const char* string,int *result) {
if (string==NULL || string[0]=='\0') {
    fatal_error("NULL or empty string in get_string_number\n");
}
return get_string_number(root,string,0,result);
}