diff options
Diffstat (limited to '')
-rw-r--r-- | src/ExcludeList.cxx (renamed from src/exclude.c) | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/exclude.c b/src/ExcludeList.cxx index 438039d30..4beb7afc3 100644 --- a/src/exclude.c +++ b/src/ExcludeList.cxx @@ -23,24 +23,23 @@ */ #include "config.h" -#include "exclude.h" +#include "ExcludeList.hxx" + +extern "C" { #include "path.h" +} #include <assert.h> #include <string.h> #include <stdio.h> #include <errno.h> -GSList * -exclude_list_load(const char *path_fs) +bool +ExcludeList::LoadFile(const char *path_fs) { - FILE *file; - char line[1024]; - GSList *list = NULL; - assert(path_fs != NULL); - file = fopen(path_fs, "r"); + FILE *file = fopen(path_fs, "r"); if (file == NULL) { if (errno != ENOENT) { char *path_utf8 = fs_charset_to_utf8(path_fs); @@ -49,9 +48,10 @@ exclude_list_load(const char *path_fs) g_free(path_utf8); } - return NULL; + return false; } + char line[1024]; while (fgets(line, sizeof(line), file) != NULL) { char *p = strchr(line, '#'); if (p != NULL) @@ -59,37 +59,24 @@ exclude_list_load(const char *path_fs) p = g_strstrip(line); if (*p != 0) - list = g_slist_prepend(list, g_pattern_spec_new(p)); + patterns.emplace_front(p); } fclose(file); - return list; -} - -void -exclude_list_free(GSList *list) -{ - while (list != NULL) { - GPatternSpec *pattern = list->data; - g_pattern_spec_free(pattern); - list = g_slist_remove(list, list->data); - } + return true; } bool -exclude_list_check(GSList *list, const char *name_fs) +ExcludeList::Check(const char *name_fs) const { assert(name_fs != NULL); /* XXX include full path name in check */ - for (; list != NULL; list = list->next) { - GPatternSpec *pattern = list->data; - - if (g_pattern_match_string(pattern, name_fs)) + for (const auto &i : patterns) + if (i.Check(name_fs)) return true; - } return false; } |