#1 Some small code cleanups.

This commit is contained in:
Per Malmberg 2019-03-13 10:28:29 +01:00
parent c20a146980
commit 6ed4bc3b2e
2 changed files with 8 additions and 16 deletions

View File

@ -142,13 +142,13 @@ namespace libcron
for (const auto& name : names)
{
std::regex m(name, std::regex_constants::ECMAScript | std::regex_constants::icase);
for (size_t i = 0; i < parts.size(); ++i)
for (auto& part : parts)
{
std::string replaced;
std::regex_replace(std::back_inserter(replaced), parts[i].begin(), parts[i].end(), m,
std::regex_replace(std::back_inserter(replaced), part.begin(), part.end(), m,
std::to_string(value_of_first_name));
parts[i] = replaced;
part = replaced;
}
value_of_first_name++;
@ -235,8 +235,8 @@ namespace libcron
if (std::regex_match(s.begin(), s.end(), match, range))
{
auto left = std::stoi(match[1].str().c_str());
auto right = std::stoi(match[2].str().c_str());
auto left = std::stoi(match[1].str());
auto right = std::stoi(match[2].str());
if (is_within_limits<T>(left, right))
{
@ -269,10 +269,10 @@ namespace libcron
}
else
{
raw_start = std::stoi(match[1].str().c_str());
raw_start = std::stoi(match[1].str());
}
auto raw_step = std::stoi(match[2].str().c_str());
auto raw_step = std::stoi(match[2].str());
if (is_within_limits<T>(raw_start, raw_start) && raw_step > 0)
{

View File

@ -90,15 +90,7 @@ namespace libcron
// Make sure that if the days contains only 31, at least one month allows that date.
if (day_of_month.size() == 1 && day_of_month.find(DayOfMonth::Last) != day_of_month.end())
{
std::vector<int32_t> months_with_31;
for (int32_t i = 1; i <= 12; ++i)
{
auto ymd = 2018_y / i / date::last;
if (unsigned(ymd.day()) == 31)
{
months_with_31.push_back(i);
}
}
constexpr std::array<uint32_t, 7> months_with_31{1, 3, 5, 7, 8, 10, 12};
res = false;
for (size_t i = 0; !res && i < months_with_31.size(); ++i)