Skip to content

Instantly share code, notes, and snippets.

@francoisdevlin
Created August 27, 2009 02:26
Show Gist options
  • Save francoisdevlin/176032 to your computer and use it in GitHub Desktop.
Save francoisdevlin/176032 to your computer and use it in GitHub Desktop.
import java.util.regex.*;
import clojure.lang.Ifn;
/**Delagates the appropraite methods to the Pattern Object
However, it adds IFn ability as well.
*/
public class ClojurePattern implements IFn, Serializable{
public static ClojurePattern compile(String regex){
return new ClojurePattern(regex,0);
}
public static ClojurePattern compile(String regex, int flags){
return new ClojurePattern(regex,flags);
}
public static String quote(String s){
return Pattern.quote(s);
}
public static boolean matches(String regex, CharSequence input){
return Pattern.matches(regex,input);
}
private final Pattern pat;
public ClojurePattern(String p,int f){
pat = new Pattern(p,f);
}
public int flags(){
return pat.flags();
}
public Matcher matcher(CharSequence input){
return pat.matcher(input);
}
public String pattern(){
return pat.pattern();
}
public String[] split(CharSequence input){
return pat.split(input);
}
public String[] split(CharSequence input, int limit){
return pat.split(input, )
}
public String toString(){
return pat.toString();
}
//Get the internal object (it's final)
public Pattern getPat(){
return pat;
}
//And now the IFn stuff...
public Object invoke(){
//same code as re-matches
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment