Skip to content

Commit

Permalink
Simplify interval syntax detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoute committed Jun 10, 2024
1 parent e8f0fc3 commit c5853f4
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/common/cron.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "cron.h"

#include <regex>
#include <stdexcept>
#include <utility>

Expand Down Expand Up @@ -116,16 +115,13 @@ StatusOr<int> Cron::convertParam(const std::string &param, 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<int>(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<int>(param, {lower_bound, upper_bound}, 10);
Expand Down

0 comments on commit c5853f4

Please sign in to comment.