Exemplo n.º 1
0
int64_t CrontabSelector::parseValue(
    const dynamic& d,
    function<int64_t(const string& lc_str)> str_to_value) {

  int64_t res;
  if (d.isInt()) {
    res = d.asInt();
  } else if (d.isString()) {
    auto s = d.asString();
    if (str_to_value == nullptr) {
      throw runtime_error("Cannot parse string " + s);
    }
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    res = str_to_value(s);
  } else {
    throw runtime_error(format("Cannot parse {}", folly::toJson(d)).str());
  }
  if (res < minVal_ || res > maxVal_) {
    throw runtime_error(format(
      "Value {} out of range [{}, {}]", res, minVal_, maxVal_
    ).str());
  }
  return res;
}
Exemplo n.º 2
0
 explicit SizeValidator(const dynamic& schema, dynamic::Type type)
     : length_(-1), type_(type) {
   if (schema.isInt()) {
     length_ = schema.getInt();
   }
 }