Skip to content

Instantly share code, notes, and snippets.

@ankitdbst
Created August 12, 2012 04:58
Show Gist options
  • Save ankitdbst/3329840 to your computer and use it in GitHub Desktop.
Save ankitdbst/3329840 to your computer and use it in GitHub Desktop.
Sort the language strings in Moodle repository_plugin.php in lang/
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SortLanguageStrings {
private static final String REGEX = "\\$string\\[\\'(.*)\\'\\].*";
public static void main( String args[] ) {
// Compile pattern
Pattern p = Pattern.compile(REGEX);
// Create a hash map
TreeMap tm = new TreeMap();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
while (true) {
String langString = br.readLine();
Matcher m = p.matcher(langString); // get a matcher object
while(m.find()) {
tm.put(m.group(1), langString);
}
}
} catch (Exception e) {
// No catch block
}
// Get a set of the entries
Set set = tm.entrySet();
Iterator i = set.iterator();
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.println(me.getValue());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment