From d19de56b4f07ae418f7f1584b82ef01ddb248a30 Mon Sep 17 00:00:00 2001 From: Per Malmberg Date: Thu, 8 Mar 2018 23:44:12 -0800 Subject: [PATCH] Don't need to pass the offset, it can be derived from T::First. --- libcron/CronTime.cpp | 4 ++-- libcron/CronTime.h | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libcron/CronTime.cpp b/libcron/CronTime.cpp index 9fe113e..8ddba7d 100644 --- a/libcron/CronTime.cpp +++ b/libcron/CronTime.cpp @@ -31,8 +31,8 @@ namespace libcron valid &= validate_numeric(match[2], minutes); valid &= validate_numeric(match[3], hours); valid &= validate_numeric(match[4], day_of_month); - valid &= validate_literal(match[5], months, month_names, 1); - valid &= validate_literal(match[6], day_of_week, day_names, 0); + valid &= validate_literal(match[5], months, month_names); + valid &= validate_literal(match[6], day_of_week, day_names); } } diff --git a/libcron/CronTime.h b/libcron/CronTime.h index ad8c013..b3a5a3d 100644 --- a/libcron/CronTime.h +++ b/libcron/CronTime.h @@ -81,8 +81,7 @@ namespace libcron template bool validate_literal(const std::string& s, std::set& numbers, - const std::vector& names, - int32_t name_offset); + const std::vector& names); template bool process_parts(const std::vector& parts, std::set& numbers); @@ -138,11 +137,12 @@ namespace libcron template bool CronTime::validate_literal(const std::string& s, std::set& numbers, - const std::vector& names, - int32_t name_offset) + const std::vector& names) { std::vector parts = split(s, ','); + auto value_of_first_name = value_of(T::First); + // Replace each found name with the corresponding value. for (const auto& name : names) { @@ -151,12 +151,12 @@ namespace libcron { std::string replaced; std::regex_replace(std::back_inserter(replaced), parts[i].begin(), parts[i].end(), m, - std::to_string(name_offset)); + std::to_string(value_of_first_name)); parts[i] = replaced; } - name_offset++; + value_of_first_name++; } return process_parts(parts, numbers);