wildcards.h
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef STIM_WILDCARDS_H
#define STIM_WILDCARDS_H
#include <sstream>
#include <iomanip>
//#include <boost/regex.hpp>
namespace stim{
class wildcards{
public:
//generate a sequence of strings where '?' is replaced by integer increments
static std::vector<std::string> increment(std::string input,
unsigned int start,
unsigned int end,
unsigned int step){
size_t a = input.find_first_of('?'); //find the first ?
size_t b = input.find_last_of('?'); //find the last ?
size_t n = b - a + 1; //calculate the number of ?
std::string str_a = input.substr(0, a); //split the strings along the wildcard
std::string str_b = input.substr(b + 1, std::string::npos);
//create a vector to hold the output strings
std::vector<std::string> out;
//create a stringstream to handle the padding
for (unsigned int i = start; i <= end; i += step){
std::stringstream ss;
ss << str_a
<< std::setfill('0')
<< std::setw(n)
<< i
<< str_b;
out.push_back(ss.str());
}
return out;
}
/*
//returns a list of files that match the specified wildcards in 'd'
static std::vector<std::string> get_file_list(std::string s){
stim::filename f(s);
std::string target_path(f.dir());
boost::regex filter(f.name());
std::vector< std::string > all_matching_files;
boost::filesystem::directory_iterator end_itr; // Default ctor yields past-the-end
for( boost::filesystem::directory_iterator i( target_path ); i != end_itr; ++i )
{
// Skip if not a file
if( !boost::filesystem::is_regular_file( i->status() ) ) continue;
boost::smatch what;
// Skip if no match
if( !boost::regex_match( i->path().filename().string(), what, filter ) ) continue;
// File matches, store it
all_matching_files.push_back( i->path().filename().string() );
}
return all_matching_files;
}
*/
};
} //end namespace stim
#endif