Commit 65be3e81 authored by Davis King's avatar Davis King

Added match_endings to the dir_nav utils.

parent 9db07ff3
......@@ -8,6 +8,7 @@
#include <algorithm>
#include "dir_nav_extensions_abstract.h"
#include "../dir_nav.h"
#include "../string.h"
namespace dlib
{
......@@ -83,6 +84,40 @@ namespace dlib
std::string ending;
};
// ----------------------------------------------------------------------------------------
class match_endings
{
public:
match_endings (
const std::string& endings_
)
{
const std::vector<std::string>& s = split(endings_);
for (unsigned long i = 0; i < s.size(); ++i)
{
endings.push_back(match_ending(s[i]));
}
}
bool operator() (
const file& f
) const
{
for (unsigned long i = 0; i < endings.size(); ++i)
{
if (endings[i](f))
return true;
}
return false;
}
private:
std::vector<match_ending> endings;
};
// ----------------------------------------------------------------------------------------
class match_all
......
......@@ -68,6 +68,43 @@ namespace dlib
!*/
};
// ----------------------------------------------------------------------------------------
class match_endings
{
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple function object that can be used with the
above get_files_in_directory_tree() function. This object
allows you to look for files with a number of different
endings.
!*/
public:
match_endings (
const std::string& ending_list
);
/*!
ensures
- ending_list is interpreted as a whitespace separated list
of file endings.
- this object will be a function that checks if a file has a
name that ends with one of the strings in ending_list.
!*/
bool operator() (
const file& f
) const;
/*!
ensures
- if (the file f has a name that ends with one of the ending strings
given to this object's constructor) then
- returns true
- else
- returns false
!*/
};
// ----------------------------------------------------------------------------------------
class match_all
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment