MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / parseTimeList

Method parseTimeList

plugins/bzfscron/CronJob.cpp:80–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80std::vector<int> CronJob::parseTimeList(const std::string in, const int min, const int max) {
81 std::vector<int> vi;
82 std::string list = in;
83
84 // First things first. Find out if there's a periodicity and trim it off.
85 size_t pos = in.find("/");
86 int period = 1;
87 if (pos != std::string::npos) {
88 period = atoi(in.substr(pos + 1).c_str());
89 list = in.substr(0, pos);
90 }
91
92 // Now tokenize on ","
93 std::vector<std::string> stage1 = tokenize(list, ",", 0, false);
94 // No tokens? That's cool too.
95 if (stage1.size() == 0) { stage1.push_back(list); }
96
97 // And for each token, blow up any "-" ranges and "*" ranges.
98 for (std::vector<std::string>::iterator itr = stage1.begin(); itr != stage1.end(); ++itr) {
99 if ((*itr).find("*") != std::string::npos) {
100 bz_debugMessage(4, "bzfscron: exploding * range");
101 for (int i = min; i <= max; ++i) {
102 vi.push_back(i);
103 }
104 }
105 else if ((pos = (int)(*itr).find("-")) != std::string::npos) {
106 bz_debugMessage(4, "bzfscron: exploding x-y range");
107 int rmin = 0, rmax = 0;
108 rmin = atoi((*itr).substr(0, pos).c_str());
109 rmax = atoi((*itr).substr(pos + 1).c_str());
110 if (rmin < min) { rmin = min; }
111 if (rmax > max) { rmax = max; }
112 for (int i = rmin; i <= rmax; ++i) {
113 vi.push_back(i);
114 }
115 }
116 else {
117 bz_debugMessage(4, "bzfscron: using single int");
118 vi.push_back(atoi((*itr).c_str()));
119 }
120 }
121
122 // Remember that periodicity we got rid of earlier? Now we need it.
123 // Eliminate any elements which disagree with the periodicity.
124 if (period > 1) {
125 std::vector<int> vp;
126 for (std::vector<int>::iterator itr2 = vi.begin(); itr2 != vi.end(); ++itr2) {
127 if (((*itr2) == 0) || ((*itr2) % period == 0)) {
128 vp.push_back(*itr2);
129 }
130 }
131 return vp;
132 }
133 else {
134 return vi;
135 }
136}
137

Callers

nothing calls this directly

Calls 8

bz_debugMessageFunction · 0.85
c_strMethod · 0.80
tokenizeFunction · 0.50
findMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected