} Bookmark;
static GList *load(const char *file);
+static gboolean bookmark_contains_all_tags(Bookmark *bm, char **query,
+ unsigned int qlen);
static Bookmark *line_to_bookmark(const char *line);
static int bookmark_comp(Bookmark *a, Bookmark *b);
static void free_bookmark(Bookmark *bm);
for (GList *l = src; l; l = l->next) {
bm = (Bookmark*)l->data;
- if (bm->tags
- && util_array_contains_all_tags(bm->tags, g_strv_length(bm->tags), parts, len)
- ) {
+ if (bookmark_contains_all_tags(bm, parts, len)) {
gtk_list_store_append(store, &iter);
gtk_list_store_set(
store, &iter,
);
}
+/**
+ * Checks if the given bookmark have all given query strings as prefix.
+ */
+static gboolean bookmark_contains_all_tags(Bookmark *bm, char **query,
+ unsigned int qlen)
+{
+ unsigned int i, n, tlen;
+
+ if (!qlen || !bm->tags || !(tlen = g_strv_length(bm->tags))) {
+ return true;
+ }
+
+ /* iterate over all query parts */
+ for (i = 0; i < qlen; i++) {
+ gboolean found = false;
+ for (n = 0; n < tlen; n++) {
+ if (g_str_has_prefix(bm->tags[n], query[i])) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static Bookmark *line_to_bookmark(const char *line)
{
char **parts;
static GList *load(const char *file);
static void write_to_file(GList *list, const char *file);
static History *line_to_history(const char *line);
+static gboolean history_item_contains_all_tags(History *item, char **query,
+ unsigned int qlen);
static int history_comp(History *a, History *b);
static void free_history(History *item);
for (GList *l = src; l; l = l->next) {
item = l->data;
- if (util_string_contains_all_tags(item->first, parts, len)) {
+ if (history_item_contains_all_tags(item, parts, len)) {
gtk_list_store_append(store, &iter);
gtk_list_store_set(
store, &iter,
return item;
}
+/**
+ * Checks if the given array of tags are all found in history item.
+ */
+static gboolean history_item_contains_all_tags(History *item, char **query,
+ unsigned int qlen)
+{
+ unsigned int i;
+ if (!qlen) {
+ return true;
+ }
+
+ /* iterate over all query parts */
+ for (i = 0; i < qlen; i++) {
+ if (!util_strcasestr(item->first, query[i])) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static int history_comp(History *a, History *b)
{
/* compare only the first part */
return NULL;
}
-
-/**
- * Checks if the given source array of pointer are prefixes to all those
- * entries given as array of search strings.
- */
-gboolean util_array_contains_all_tags(char **src, unsigned int s, char **query, unsigned int q)
-{
- unsigned int i, n;
-
- if (!s || !q) {
- return true;
- }
-
- /* iterate over all query parts */
- for (i = 0; i < q; i++) {
- gboolean found = false;
- for (n = 0; n < s; n++) {
- if (g_str_has_prefix(src[n], query[i])) {
- found = true;
- break;
- }
- }
- if (!found) {
- return false;
- }
- }
-
- return true;
-}
-
-/**
- * Checks if the given array of tags are all found in source string.
- */
-gboolean util_string_contains_all_tags(char *src, char **query, unsigned int q)
-{
- unsigned int i;
- if (!q) {
- return true;
- }
-
- /* iterate over all query parts */
- for (i = 0; i < q; i++) {
- if (!util_strcasestr(src, query[i])) {
- return false;
- }
- }
-
- return true;
-}
-
/**
* Replaces appearances of search in string by given replace.
* Returne a new allocated string of search was found.
GList *util_file_to_unique_list(const char *filename, Util_Content_Func func,
GCompareFunc unique_func, GDestroyNotify free_func);
char* util_strcasestr(const char* haystack, const char* needle);
-gboolean util_array_contains_all_tags(char **src, unsigned int s, char **query, unsigned int q);
-gboolean util_string_contains_all_tags(char *src, char **query, unsigned int q);
char *util_str_replace(const char* search, const char* replace, const char* string);
gboolean util_create_tmp_file(const char *content, char **file);
char *util_build_path(const char *path, const char *dir);