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; }
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(); } }