コード例 #1
0
static void GenStat(Stat* s, UJObject v) {
	switch (UJGetType(v)) {
	case UJT_Object:
		{
			void* iter = UJBeginObject(v);
			UJString key;
			UJObject value;
			while (UJIterObject(&iter, &key, &value)) {
				s->memberCount++;
				s->stringCount++;
				s->stringLength += key.cchLen;
				GenStat(s, value);
			}
			s->objectCount++;
		}
		break;

	case UJT_Array:
		{
			void* iter = UJBeginArray(v);
			UJObject value;
			while (UJIterArray(&iter, &value)) {
				GenStat(s, value);
				s->elementCount++;
			}
			s->arrayCount++;
		}
		break;

	case UJT_String:
		{
			size_t length;
			UJReadString(v, &length);
			s->stringCount++;  
			s->stringLength += length;
		}
		break;

	case UJT_Long: 
	case UJT_LongLong:
	case UJT_Double:
		s->numberCount++;  break;

	case UJT_True: s->trueCount++; break;
	case UJT_False: s->falseCount++; break;
	case UJT_Null: s->nullCount++; break;
    default:;
    }
}
コード例 #2
0
ファイル: ujdecode.c プロジェクト: MikeAthene/ujson4c
static int checkType(int ki, const char *format, UJObject obj)
{
	int c = (unsigned char) format[ki];
	int type = UJGetType(obj);
	int allowNull = 0;

	switch (c)
	{
	case 'b':
		allowNull = 1;
	case 'B':
		switch (type)
		{
			case UJT_Null:
				if (!allowNull)
					return 0;
			case UJT_True:
			case UJT_False:
				return 1;

			default:
				return 0;
		}
		break;

	case 'n':
		allowNull = 1;
	case 'N':
		switch (type)
		{
			case UJT_Null:
				if (!allowNull)
					return 0;
			case UJT_Long:
			case UJT_LongLong:
			case UJT_Double:
				return 1;

			default:
				return 0;
		}
		break;

	case 's':
		allowNull = 1;
	case 'S':
		switch (type)
		{
			case UJT_Null:
				if (!allowNull)
					return 0;
			case UJT_String:
				return 1;

			default:
				return 0;
		}
		break;

	case 'a':
		allowNull = 1;
	case 'A':
		switch (type)
		{
			case UJT_Null:
				if (!allowNull)
					return 0;
			case UJT_Array:
				return 1;

			default:
				return 0;
		}
		break;

	case 'o':
		allowNull = 1;
	case 'O':
		switch (type)
		{
			case UJT_Null:
				if (!allowNull)
					return 0;
			case UJT_Object:
				return 1;
			default:
				return 0;
		}

		break;

	case 'u':
		allowNull = 1;
	case 'U':
		return 1;
		break;
	}

	return 0;
}