/*
* Create validation error
*/
-static void
+
+#ifdef __GNUC__
+static inline void
+ucl_schema_create_error (struct ucl_schema_error *err,
+ enum ucl_schema_error_code code, const ucl_object_t *obj,
+ const char *fmt, ...)
+__attribute__ (( format( printf, 4, 5) ));
+#endif
+
+static inline void
ucl_schema_create_error (struct ucl_schema_error *err,
enum ucl_schema_error_code code, const ucl_object_t *obj,
const char *fmt, ...)
* Check whether we have a pattern specified
*/
static const ucl_object_t *
-ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern)
+ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern, bool recursive)
{
const ucl_object_t *res = NULL;
#ifdef HAVE_REGEX_H
ucl_object_iter_t iter = NULL;
if (regcomp (®, pattern, REG_EXTENDED | REG_NOSUB) == 0) {
- while ((elt = ucl_object_iterate (obj, &iter, true)) != NULL) {
- if (regexec (®, ucl_object_key (elt), 0, NULL, 0) == 0) {
- res = elt;
- break;
+ if (recursive) {
+ while ((elt = ucl_object_iterate (obj, &iter, true)) != NULL) {
+ if (regexec (®, ucl_object_key (elt), 0, NULL, 0) == 0) {
+ res = elt;
+ break;
+ }
}
+ } else {
+ if (regexec (®, ucl_object_key (obj), 0, NULL, 0) == 0)
+ res = obj;
}
regfree (®);
}
}
}
else if (strcmp (ucl_object_key (elt), "patternProperties") == 0) {
+ const ucl_object_t *vobj;
+ ucl_object_iter_t viter;
piter = NULL;
while (ret && (prop = ucl_object_iterate (elt, &piter, true)) != NULL) {
- found = ucl_schema_test_pattern (obj, ucl_object_key (prop));
- if (found) {
- ret = ucl_schema_validate (prop, found, true, err, root,
- ext_ref);
+ viter = NULL;
+ while (ret && (vobj = ucl_object_iterate (obj, &viter, true)) != NULL) {
+ found = ucl_schema_test_pattern (vobj, ucl_object_key (prop), false);
+ if (found) {
+ ret = ucl_schema_validate (prop, found, true, err, root,
+ ext_ref);
+ }
}
}
}
piter = NULL;
pat = ucl_object_lookup (schema, "patternProperties");
while ((pelt = ucl_object_iterate (pat, &piter, true)) != NULL) {
- found = ucl_schema_test_pattern (obj, ucl_object_key (pelt));
+ found = ucl_schema_test_pattern (obj, ucl_object_key (pelt), true);
if (found != NULL) {
break;
}
if (fabs (remainder (val, constraint)) > alpha) {
ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
"number %.4f is not multiple of %.4f, remainder is %.7f",
- val, constraint);
+ val, constraint, remainder (val, constraint));
ret = false;
break;
}
constraint = ucl_object_toint (elt);
if (obj->len > constraint) {
ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
- "string is too big: %.3f, maximum is: %.3f",
+ "string is too big: %u, maximum is: %" PRId64,
obj->len, constraint);
ret = false;
break;
constraint = ucl_object_toint (elt);
if (obj->len < constraint) {
ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
- "string is too short: %.3f, minimum is: %.3f",
+ "string is too short: %u, minimum is: %" PRId64,
obj->len, constraint);
ret = false;
break;