Exemplo n.º 1
0
 Optional<SchemaError> validate(ValidationContext&,
                                const dynamic& value) const override {
   if (!value.isString() || regex_.empty()) {
     return none;
   }
   if (!boost::regex_search(value.getString().toStdString(), regex_)) {
     return makeError("string matching regex", value);
   }
   return none;
 }
Exemplo n.º 2
0
 explicit TypeValidator(const dynamic& schema) {
   if (schema.isString()) {
     addType(schema.stringPiece());
   } else if (schema.isArray()) {
     for (const auto& item : schema) {
       if (item.isString()) {
         addType(item.stringPiece());
       }
     }
   }
 }
Exemplo n.º 3
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.º 4
0
 explicit StringPatternValidator(const dynamic& schema) {
   if (schema.isString()) {
     regex_ = boost::regex(schema.getString().toStdString());
   }
 }