/* glob must be valid UTF-8 */ static XdgGlobHashNode * _xdg_glob_hash_insert_text (XdgGlobHashNode * glob_hash_node, const char *text, const char *mime_type, int weight) { XdgGlobHashNode *node; xdg_unichar_t *unitext; int len; unitext = _xdg_convert_to_ucs4 (text, &len); _xdg_reverse_ucs4 (unitext, len); node = _xdg_glob_hash_insert_ucs4 (glob_hash_node, unitext, mime_type, weight); free (unitext); return node; }
static XdgGlobHashNode * _xdg_glob_hash_insert_ucs4 (XdgGlobHashNode *glob_hash_node, xdg_unichar_t *text, const char *mime_type, int weight, int case_sensitive) { XdgGlobHashNode *node; xdg_unichar_t character; character = text[0]; if ((glob_hash_node == NULL) || (character < glob_hash_node->character)) { node = _xdg_glob_hash_node_new (); node->character = character; node->next = glob_hash_node; glob_hash_node = node; } else if (character == glob_hash_node->character) { node = glob_hash_node; } else { XdgGlobHashNode *prev_node; int found_node = FALSE; /* Look for the first character of text in glob_hash_node, and insert it if we * have to.*/ prev_node = glob_hash_node; node = prev_node->next; while (node != NULL) { if (character < node->character) { node = _xdg_glob_hash_node_new (); node->character = character; node->next = prev_node->next; prev_node->next = node; found_node = TRUE; break; } else if (character == node->character) { found_node = TRUE; break; } prev_node = node; node = node->next; } if (! found_node) { node = _xdg_glob_hash_node_new (); node->character = character; node->next = prev_node->next; prev_node->next = node; } } text++; if (*text == 0) { if (node->mime_type) { if (strcmp (node->mime_type, mime_type) != 0) { XdgGlobHashNode *child; int found_node = FALSE; child = node->child; while (child && child->character == 0) { if (strcmp (child->mime_type, mime_type) == 0) { found_node = TRUE; break; } child = child->next; } if (!found_node) { child = _xdg_glob_hash_node_new (); child->character = 0; child->mime_type = strdup (mime_type); child->weight = weight; child->case_sensitive = case_sensitive; child->child = NULL; child->next = node->child; node->child = child; } } } else { node->mime_type = strdup (mime_type); node->weight = weight; node->case_sensitive = case_sensitive; } } else { node->child = _xdg_glob_hash_insert_ucs4 (node->child, text, mime_type, weight, case_sensitive); } return glob_hash_node; }