From 6ed4bc3b2ed9f271659b81d630fab44e930219d0 Mon Sep 17 00:00:00 2001 From: Per Malmberg Date: Wed, 13 Mar 2019 10:28:29 +0100 Subject: [PATCH] #1 Some small code cleanups. --- libcron/include/libcron/CronData.h | 14 +++++++------- libcron/src/CronData.cpp | 10 +--------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/libcron/include/libcron/CronData.h b/libcron/include/libcron/CronData.h index c402517..94ede9b 100644 --- a/libcron/include/libcron/CronData.h +++ b/libcron/include/libcron/CronData.h @@ -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(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(raw_start, raw_start) && raw_step > 0) { diff --git a/libcron/src/CronData.cpp b/libcron/src/CronData.cpp index 6c08f59..dcfb902 100644 --- a/libcron/src/CronData.cpp +++ b/libcron/src/CronData.cpp @@ -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 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 months_with_31{1, 3, 5, 7, 8, 10, 12}; res = false; for (size_t i = 0; !res && i < months_with_31.size(); ++i)