Example #1
0
static bool hasJsonValue(sajson::value jsonObject, const char* key, sajson::type expectedType) {
	size_t index = jsonObject.find_object_key(sajson::literal(key));
	if (index == jsonObject.get_length()) {
		return false;
	}
	sajson::value value = jsonObject.get_object_value(index);
	return value.get_type() == expectedType;
}
Example #2
0
double traverse_sajson(const sajson::value &v)
{
	double x = 0;
	switch (v.get_type())
	{
		case sajson::TYPE_DOUBLE:
			x += v.get_double_value();
			break;
		case sajson::TYPE_INTEGER:
			x += v.get_integer_value();
			break;
		case sajson::TYPE_ARRAY:
			for (size_t i = 0; i < v.get_length(); ++i)
			{
				x += traverse_sajson(v.get_array_element(i));
			}
			break;
		case sajson::TYPE_OBJECT:
			for (size_t i = 0; i < v.get_length(); ++i)
			{
				x += traverse_sajson(v.get_object_value(i));
			}
			break;
		default:
			return 0;
	}
	return x;
}
Example #3
0
static vector<string> extractClassPath(const sajson::value& classPath) {

	size_t count = classPath.get_length();
	vector<string> paths;

	for (size_t cp = 0; cp < count; cp++) {

		string classPathURL = classPath.get_array_element(cp).as_string();

		// TODO: don't just test for file extension
		if (classPathURL.rfind(".txt") != classPathURL.length() - 4) {

			paths.push_back(classPathURL);

		} else {

			ifstream txt(classPathURL.c_str());
			string line;

			while (!txt.eof()) {

				txt >> line;

				if (line.find("-classpath") == 0) {

					txt >> line;

					istringstream iss(line);
					string path;

					while (getline(iss, path, __CLASS_PATH_DELIM)) {
						paths.push_back(path);
					}

					break;
				}

			}

			txt.close();

		}

	}
Example #4
0
static sajson::value getJsonValue(sajson::value jsonObject, const char* key) {
	size_t index = jsonObject.find_object_key(sajson::literal(key));
	return jsonObject.get_object_value(index);
}