aboutsummaryrefslogtreecommitdiff
path: root/0.8.0/paludis/util/is_file_with_extension.cc
diff options
context:
space:
mode:
Diffstat (limited to '0.8.0/paludis/util/is_file_with_extension.cc')
-rw-r--r--0.8.0/paludis/util/is_file_with_extension.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/0.8.0/paludis/util/is_file_with_extension.cc b/0.8.0/paludis/util/is_file_with_extension.cc
new file mode 100644
index 000000000..9655b5e4b
--- /dev/null
+++ b/0.8.0/paludis/util/is_file_with_extension.cc
@@ -0,0 +1,56 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/util/is_file_with_extension.hh>
+
+using namespace paludis;
+
+/** \file
+ * Implementation of IsFileWithExtension.
+ *
+ * \ingroup grpfilesystem
+ */
+
+IsFileWithExtension::IsFileWithExtension(const std::string & ext) :
+ _prefix(""),
+ _ext(ext)
+{
+}
+
+IsFileWithExtension::IsFileWithExtension(const std::string & prefix, const std::string & ext) :
+ _prefix(prefix),
+ _ext(ext)
+{
+}
+
+bool
+IsFileWithExtension::operator() (const FSEntry & f) const
+{
+ const std::string filename(f.basename());
+
+ if (filename.length() < _ext.length() + _prefix.length())
+ return false;
+ if (0 != filename.compare(filename.length() - _ext.length(),
+ _ext.length(), _ext))
+ return false;
+ if (0 != filename.compare(0, _prefix.length(), _prefix))
+ return false;
+ return f.is_regular_file() || (f.exists() && f.realpath().is_regular_file());
+}
+