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
int UJObjectUnpack(UJObject objObj, int keys, const char *format, const wchar_t **_keyNames, ...)
{
	void *iter;
	UJString key;
	UJObject value;
	int found = 0;
	int ki;
	int ks = 0;
	const wchar_t *keyNames[64];
  va_list args;
  UJObject *outValue;

  va_start(args, _keyNames);

  if (!UJIsObject(objObj))
	{
		return 0;
	}
  
	iter = UJBeginObject(objObj);

	if (keys > 64)
	{
		return -1;
	}

	for (ki = 0; ki < keys; ki ++)
	{
		keyNames[ki] = _keyNames[ki];
	}
	
	while (UJIterObject(&iter, &key, &value))
	{
		for (ki = ks; ki < keys; ki ++)
		{
			const wchar_t *kn = keyNames[ki];

			if (kn == NULL)
			{
				continue;
			}

			if (wcscmp(key.ptr, kn) != 0)
			{
				continue;
			}

			if (!checkType(ki, format, value))
			{
				continue;
			}

			found ++;

      outValue = va_arg(args, UJObject *);

      if (outValue != NULL)
      {
  			*outValue = value;
      }
			keyNames[ki] = NULL;

			if (ki == ks)
			{
				ks ++;
			}
		}
	}

  va_end(args);

	return found;
}