}});
super.put("regexp", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
- //throw new Error("not implemented");
- Log.log(XWT.class, "regexp not implemented");
- return null;
+ return new Regexp(args);
}});
super.put("listfonts", new JS.Callable() { public Object call(JS.Array args) throws JS.Exn {
if (args.length() != 1) return null;
return new Integer(((String)o).indexOf(args.elementAt(0).toString()));
} };
- // This is just a quick and dirty split implementation. its could be optimized a lot and it doesn't
- // do regexps yet. this will need to be rewritten when we get regexp support anyway
- else if (v.equals("split")) return new JS.Callable() {
+ else if(v.equals("match")) return new JS.Callable() {
public Object call(JS.Array args) {
- String sep;
- int limit, s,p,matches=0;
- int seplen;
- JS.Array ret;
-
- if(args.length() > 1) limit = JS.toNumber(args.elementAt(1)).intValue();
- else limit = 0;
- if(args.length() > 0) sep = args.elementAt(0).toString();
- else sep = null;
-
- seplen = sep!=null ? sep.length() : 0;
-
- // special case sep == null, split up chars
- if(seplen == 0) {
- ret = new JS.Array(o.length());
- for(int i=0;i<o.length();i++) ret.setElementAt(o.substring(i,i+1),i);
- return ret;
- }
- ret = new JS.Array();
- for(s=0;(limit<=0 || matches < limit-1) && (p = o.indexOf(sep,s)) != -1;s=p+seplen) {
- ret.addElement(o.substring(s,p));
- matches++;
- }
- if(s != o.length()) ret.addElement(o.substring(s));
- return ret;
+ return Regexp.stringMatch(o,args);
+ } };
+ else if(v.equals("search")) return new JS.Callable() {
+ public Object call(JS.Array args) {
+ return Regexp.stringSearch(o,args);
+ } };
+ else if(v.equals("replace")) return new JS.Callable() {
+ public Object call(JS.Array args) {
+ return Regexp.stringReplace(o,args);
+ } };
+ else if(v.equals("split")) return new JS.Callable() {
+ public Object call(JS.Array args) {
+ return Regexp.stringSplit(o,args);
} };