Re: [mpd-devel] [PATCH] db/update/ExcludeList: implement with std::regex

2015-05-29 Thread Max Kellermann
On 2015/05/22 09:04, Thomas Guillem  wrote:
> ---
> New version that use std::regex instead of regex.h.

That is an incompatible change, and will break everybody's .mpdignore
files!

___
mpd-devel mailing list
mpd-devel@musicpd.org
http://mailman.blarg.de/listinfo/mpd-devel


[mpd-devel] [PATCH] db/update/ExcludeList: implement with std::regex

2015-05-22 Thread Thomas Guillem
---
New version that use std::regex instead of regex.h.

 src/db/update/ExcludeList.cxx | 18 +-
 src/db/update/ExcludeList.hxx | 23 +--
 2 files changed, 10 insertions(+), 31 deletions(-)

diff --git a/src/db/update/ExcludeList.cxx b/src/db/update/ExcludeList.cxx
index 631d452..832828b 100644
--- a/src/db/update/ExcludeList.cxx
+++ b/src/db/update/ExcludeList.cxx
@@ -35,26 +35,27 @@
 #include 
 #include 
 
-#ifdef HAVE_GLIB
-
 gcc_pure
 static bool
 IsFileNotFound(const Error &error)
 {
+#ifdef HAVE_GLIB
 #ifdef WIN32
return error.IsDomain(win32_domain) &&
error.GetCode() == ERROR_FILE_NOT_FOUND;
 #else
return error.IsDomain(errno_domain) && error.GetCode() == ENOENT;
 #endif
+#else
+   (void) error;
+   return true;
+#endif
 }
 
-#endif
 
 bool
 ExcludeList::LoadFile(Path path_fs)
 {
-#ifdef HAVE_GLIB
Error error;
TextFile file(path_fs, error);
if (file.HasFailed()) {
@@ -73,10 +74,6 @@ ExcludeList::LoadFile(Path path_fs)
if (*p != 0)
patterns.emplace_front(p);
}
-#else
-   // TODO: implement
-   (void)path_fs;
-#endif
 
return true;
 }
@@ -88,14 +85,9 @@ ExcludeList::Check(Path name_fs) const
 
/* XXX include full path name in check */
 
-#ifdef HAVE_GLIB
for (const auto &i : patterns)
if (i.Check(NarrowPath(name_fs).c_str()))
return true;
-#else
-   // TODO: implement
-   (void)name_fs;
-#endif
 
return false;
 }
diff --git a/src/db/update/ExcludeList.hxx b/src/db/update/ExcludeList.hxx
index ae196a7..b81f262 100644
--- a/src/db/update/ExcludeList.hxx
+++ b/src/db/update/ExcludeList.hxx
@@ -30,50 +30,37 @@
 
 #include 
 
-#ifdef HAVE_GLIB
-#include 
-#endif
+#include 
 
 class Path;
 
 class ExcludeList {
-#ifdef HAVE_GLIB
class Pattern {
-   GPatternSpec *pattern;
+   std::regex pattern;
 
public:
Pattern(const char *_pattern)
-   :pattern(g_pattern_spec_new(_pattern)) {}
+   :pattern(_pattern) {}
 
Pattern(Pattern &&other)
:pattern(other.pattern) {
other.pattern = nullptr;
}
 
-   ~Pattern() {
-   g_pattern_spec_free(pattern);
-   }
+   ~Pattern() {}
 
gcc_pure
bool Check(const char *name_fs) const {
-   return g_pattern_match_string(pattern, name_fs);
+   return regex_match(name_fs, pattern);
}
};
 
std::forward_list patterns;
-#else
-   // TODO: implement
-#endif
 
 public:
gcc_pure
bool IsEmpty() const {
-#ifdef HAVE_GLIB
return patterns.empty();
-#else
-   // TODO: implement
-   return true;
-#endif
}
 
/**
-- 
2.1.4

___
mpd-devel mailing list
mpd-devel@musicpd.org
http://mailman.blarg.de/listinfo/mpd-devel