use of net.sf.json.JSONArray in project compiler by boalang.
the class GetGithubRepoLanguagesMulti method getLanguages.
private static ArrayList<GithubLanguage> getLanguages(String content) {
ArrayList<GithubLanguage> languages = new ArrayList<GithubLanguage>();
JSONArray repos = null;
try {
repos = (JSONArray) JSONSerializer.toJSON(content);
} catch (JSONException e) {
}
if (repos == null) {
System.err.println("Error parsing file\n" + content);
return languages;
}
int status = 0, s = 0;
String name = null, count;
for (int i = 0; i < content.length(); i++) {
if (status == 0 && content.charAt(i) == '\"') {
status = 1;
s = i + 1;
} else if (status == 1 && content.charAt(i) == '\"') {
status = 2;
name = content.substring(s, i);
} else if (status == 2 && content.charAt(i) == ':') {
status = 3;
s = i + 1;
} else if (status == 3 && !Character.isDigit(content.charAt(i))) {
status = 0;
count = content.substring(s, i);
languages.add(new GithubLanguage(name, count));
}
}
return languages;
}
Aggregations