Beispiel #1
0
static bool _check(Validator *v, ValidationEvent const *e, ValidationState *s, void *ctxt)
{
	if (e->type != EV_NUM)
	{
		validation_state_notify_error(s, VEC_NOT_NUMBER, ctxt);
		validation_state_pop_validator(s);
		return false;
	}

	Number n;
	number_init(&n);
	if (number_set_n(&n, e->value.string.ptr, e->value.string.len))
	{
		number_clear(&n);
		// TODO: Number format error
		validation_state_notify_error(s, VEC_NOT_NUMBER, ctxt);
		validation_state_pop_validator(s);
		return false;
	}

	bool res = _check_conditions((NumberValidator *) v, &n, s, ctxt);

	number_clear(&n);
	validation_state_pop_validator(s);
	return res;
}
Beispiel #2
0
static Validator* set_minimum(Validator *v, Number *num)
{
	NumberValidator *n = (NumberValidator *) v;
	n->min_set = true;
	number_init(&n->min);
	number_copy(&n->min, num);
	return v;
}
Beispiel #3
0
bool number_validator_add_max_constraint(NumberValidator *n, const char* val)
{
	Number num;
	number_init(&num);
	if (number_set(&num, val))
	{
		number_clear(&num);
		return false;
	}
	set_maximum(&n->base, &num);
	number_clear(&num);
	return true;
}
Beispiel #4
0
bool number_validator_add_expected_value(NumberValidator *n, StringSpan *span)
{
	if (n->expected_set)
		number_clear(&n->expected_value), n->expected_set = false;

	number_init(&n->expected_value);
	if (number_set_n(&n->expected_value, span->str, span->str_len))
	{
		number_clear(&n->expected_value);
		return false;
	}
	n->expected_set = true;
	return true;
}
Beispiel #5
0
static bool check_integer_generic(Validator *v, ValidationEvent const *e, ValidationState *s, void *ctxt)
{
	if (e->type != EV_NUM)
	{
		validation_state_notify_error(s, VEC_NOT_NUMBER, ctxt);
		validation_state_pop_validator(s);
		return false;
	}

	Number n;
	number_init(&n);

	bool res = check_integer_conditions(&n, e, s, ctxt);
	number_clear(&n);
	validation_state_pop_validator(s);
	return res;
}
Beispiel #6
0
number_ref number_create (void) {
	struct number *self = Calloc (1, sizeof (struct number));
	number_init (self);
	object_retain (self);
	return self;
}