From c5853f4307fa32120ac0da136f6d42019f061fd5 Mon Sep 17 00:00:00 2001 From: Yann Defretin Date: Mon, 10 Jun 2024 07:33:06 +0200 Subject: [PATCH] Simplify interval syntax detection --- src/common/cron.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/common/cron.cc b/src/common/cron.cc index d860d35b74b..baa82109b0e 100644 --- a/src/common/cron.cc +++ b/src/common/cron.cc @@ -20,7 +20,6 @@ #include "cron.h" -#include #include #include @@ -116,16 +115,13 @@ StatusOr Cron::convertParam(const std::string ¶m, int lower_bound, int } // Check for interval syntax (*/n) - std::regex interval_regex(R"(\*/(\d+))"); - std::smatch match; - if (std::regex_match(param, match, interval_regex)) { - int interval = std::stoi(match[1].str()); - if (interval >= lower_bound && interval <= upper_bound) { - is_interval = true; - return interval; - } else { - return {Status::NotOK, "interval value out of bounds"}; + if (HasPrefix(param, "*/")) { + auto s = ParseInt(param.substr(2), {lower_bound, upper_bound}, 10); + if (!s) { + return std::move(s).Prefixed(fmt::format("malformed cron token `{}`", param)); } + is_interval = true; + return *s; } auto s = ParseInt(param, {lower_bound, upper_bound}, 10);