static bool check(Validator *v, ValidationEvent const *e, ValidationState *s, void *c)
{
	ArrayValidator *varr = (ArrayValidator *) v;
	MyContext *my_ctxt = (MyContext *) validation_state_get_context(s);
	if (!my_ctxt->has_started)
	{
		if (e->type != EV_ARR_START)
		{
			validation_state_notify_error(s, VEC_NOT_ARRAY, c);
			validation_state_pop_validator(s);
			return false;
		}
		my_ctxt->has_started = true;
		my_ctxt->cur_validator = varr->items ? varr->items->validators : NULL;
		return true;
	}

	if (e->type == EV_ARR_END)
	{
		bool res = true;
		if (varr->min_items != -1 && my_ctxt->items_count < varr->min_items)
		{
			validation_state_notify_error(s, VEC_ARRAY_TOO_SHORT, c);
			res = false;
		}
		else if (varr->unique_items && s->notify && s->notify->has_array_duplicates &&
		         s->notify->has_array_duplicates(s, c))
		{
			validation_state_notify_error(s, VEC_ARRAY_HAS_DUPLICATES, c);
			res = false;
		}
		validation_state_pop_validator(s);
		return res;
	}

	++my_ctxt->items_count;

	if (varr->max_items != -1 && my_ctxt->items_count > varr->max_items)
	{
		validation_state_notify_error(s, VEC_ARRAY_TOO_LONG, c);
		validation_state_pop_validator(s);
		return false;
	}

	Validator* vcur = _get_current_validator(varr, my_ctxt);
	if (vcur)
	{
		validation_state_push_validator(s, vcur);
		bool valid = validation_check(e, s, c);
		if (!valid)
			validation_state_pop_validator(s);
		return valid;
	}

	validation_state_notify_error(s, VEC_ARRAY_TOO_LONG, c);
	validation_state_pop_validator(s);
	return false;
}
Exemple #2
0
int my_bounce_null(void *ctxt)
{
	JSAXContextRef spring = (JSAXContextRef)ctxt;
	assert(spring->m_handlers->yajl_null);

	ValidationEvent e = validation_event_null();
	if (!validation_check(&e, spring->validation_state, ctxt))
		return false;

	return spring->m_handlers->yajl_null(ctxt);
}
Exemple #3
0
int my_bounce_boolean(void *ctxt, int boolVal)
{
	JSAXContextRef spring = (JSAXContextRef)ctxt;
	assert(spring->m_handlers->yajl_boolean);

	ValidationEvent e = validation_event_boolean(boolVal);
	if (!validation_check(&e, spring->validation_state, ctxt))
		return false;

	return spring->m_handlers->yajl_boolean(ctxt, boolVal);
}
Exemple #4
0
int my_bounce_number(void *ctxt, const char *numberVal, yajl_size_t numberLen)
{
	JSAXContextRef spring = (JSAXContextRef)ctxt;
	assert(spring->m_handlers->yajl_number);

	ValidationEvent e = validation_event_number(numberVal, numberLen);
	if (!validation_check(&e, spring->validation_state, ctxt))
		return false;

	return spring->m_handlers->yajl_number(ctxt, numberVal, numberLen);
}
Exemple #5
0
int my_bounce_string(void *ctxt, const unsigned char *str, yajl_size_t strLen)
{
	JSAXContextRef spring = (JSAXContextRef)ctxt;
	assert(spring->m_handlers->yajl_string);

	ValidationEvent e = validation_event_string((char const *) str, strLen);
	if (!validation_check(&e, spring->validation_state, ctxt))
		return false;

	return spring->m_handlers->yajl_string(ctxt, str, strLen);
}
void main(void)
{
	char input[20];
	int result;
	printf("enter the input string\n");
	gets(input);
	if (validation_check(input))
		result = divisible2(input);
	else
	{
		printf("the enterd number has invalid characters\n");
		getch();
		exit(0);
	}
	if (result == 1)
		printf("the number eneterd is divisible by 11");
	else
		printf("the number entered is not divisible by 11");
	getch();
}