Skip to content

Commit

Permalink
Fix a small problem with casefull keywords
Browse files Browse the repository at this point in the history
In @1636 I miss one check for keyword case. Now it should be all fixed.
  • Loading branch information
mowgli committed Aug 1, 2009
1 parent 993581f commit 95f139c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
54 changes: 48 additions & 6 deletions src/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,17 @@ gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *value
}
}

/**
* \see find_string_in_list
*/
gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string)
{
gchar *string_casefold = g_utf8_casefold(string, -1);

while (list)
{
gchar *haystack = list->data;

if (haystack)
{
gboolean equal;
Expand All @@ -681,14 +684,53 @@ gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string)
return haystack;
}
}

list = list->next;
}

g_free(string_casefold);
return NULL;
}

/**
* \see find_string_in_list
*/
gchar *find_string_in_list_utf8case(GList *list, const gchar *string)
{
while (list)
{
gchar *haystack = list->data;

if (haystack && strcmp(haystack, string) == 0)
return haystack;

list = list->next;
} // while (list)

return NULL;
} // gchar *find_string_in_list_utf...

/**
* \brief Find a existent string in a list.
*
* This is a switch between find_string_in_list_utf8case and
* find_string_in_list_utf8nocase to search with or without case for the
* existence of a string.
*
* \param list The list to search in
* \param string The string to search for
* \return The string or NULL
*
* \see find_string_in_list_utf8case
* \see find_string_in_list_utf8nocase
*/
gchar *find_string_in_list(GList *list, const gchar *string)
{
if (options->metadata.keywords_case_sensitive)
return find_string_in_list_utf8case(list, string);
else
return find_string_in_list_utf8nocase(list, string);
}

#define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b')

Expand Down Expand Up @@ -719,7 +761,7 @@ GList *string_to_keywords_list(const gchar *text)
gchar *keyword = g_strndup(begin, l);

/* only add if not already in the list */
if (!find_string_in_list_utf8nocase(list, keyword))
if (!find_string_in_list(list, keyword))
list = g_list_append(list, keyword);
else
g_free(keyword);
Expand Down Expand Up @@ -1168,7 +1210,7 @@ void keyword_tree_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr, GList *
if (keyword_get_is_keyword(keyword_tree, &iter))
{
gchar *name = keyword_get_name(keyword_tree, &iter);
if (!find_string_in_list_utf8nocase(*kw_list, name))
if (!find_string_in_list(*kw_list, name))
{
*kw_list = g_list_append(*kw_list, name);
}
Expand All @@ -1190,7 +1232,7 @@ static void keyword_tree_reset1(GtkTreeModel *keyword_tree, GtkTreeIter *iter, G
if (!keyword_get_is_keyword(keyword_tree, iter)) return;

name = keyword_get_name(keyword_tree, iter);
found = find_string_in_list_utf8nocase(*kw_list, name);
found = find_string_in_list(*kw_list, name);

if (found)
{
Expand Down
1 change: 0 additions & 1 deletion src/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ gboolean metadata_append_string(FileData *fd, const gchar *key, const char *valu
gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *values);

GList *string_to_keywords_list(const gchar *text);
gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string);

gboolean meta_data_get_keyword_mark(FileData *fd, gint n, gpointer data);
gboolean meta_data_set_keyword_mark(FileData *fd, gint n, gboolean value, gpointer data);
Expand Down

0 comments on commit 95f139c

Please sign in to comment.