-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt.js;
import gnu.regexp.*;
}
}
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+ public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
switch(nargs) {
case 1: {
//#switch(method)
return super.callMethod(method, a0, a1, a2, rest, nargs);
}
- public Object get(Object key) {
+ public Object get(Object key) throws JSExn {
//#switch(key)
case "exec": return METHOD;
case "test": return METHOD;
return super.get(key);
}
- public void put(Object key, Object value) {
+ public void put(Object key, Object value) throws JSExn {
if(key.equals("lastIndex")) lastIndex = JS.toNumber(value).intValue();
super.put(key,value);
}
private static Object matchToExecResult(REMatch match, RE re, String s) {
- JS ret = new JS();
- ret.put("index", N(match.getStartIndex()));
- ret.put("input",s);
- int n = re.getNumSubs();
- ret.put("length", N(n+1));
- ret.put("0",match.toString());
- for(int i=1;i<=n;i++) ret.put(Integer.toString(i),match.toString(i));
- return ret;
+ try {
+ JS ret = new JS();
+ ret.put("index", N(match.getStartIndex()));
+ ret.put("input",s);
+ int n = re.getNumSubs();
+ ret.put("length", N(n+1));
+ ret.put("0",match.toString());
+ for(int i=1;i<=n;i++) ret.put(Integer.toString(i),match.toString(i));
+ return ret;
+ } catch (JSExn e) {
+ throw new Error("this should never happen");
+ }
}
public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append('/');
- sb.append(get("source"));
- sb.append('/');
- if(global) sb.append('g');
- if(Boolean.TRUE.equals(get("ignoreCase"))) sb.append('i');
- if(Boolean.TRUE.equals(get("multiline"))) sb.append('m');
- return sb.toString();
+ try {
+ StringBuffer sb = new StringBuffer();
+ sb.append('/');
+ sb.append(get("source"));
+ sb.append('/');
+ if(global) sb.append('g');
+ if(Boolean.TRUE.equals(get("ignoreCase"))) sb.append('i');
+ if(Boolean.TRUE.equals(get("multiline"))) sb.append('m');
+ return sb.toString();
+ } catch (JSExn e) {
+ throw new Error("this should never happen");
+ }
}
public static Object stringMatch(Object o, Object arg0) throws JSExn {
public static Object stringReplace(Object o, Object arg0, Object arg1) throws JSExn {
String s = o.toString();
RE re;
- JS replaceFunc = null;
+ JSFunction replaceFunc = null;
String replaceString = null;
JSRegexp regexp = null;
if(arg0 instanceof JSRegexp) {
} else {
re = newRE(arg0.toString(),0);
}
- if(arg1 instanceof JS)
- replaceFunc = (JS) arg1;
+ if(arg1 instanceof JSFunction)
+ replaceFunc = (JSFunction) arg1;
else
- replaceString = arg1.toString();
+ replaceString = JS.toString(arg1.toString());
REMatch[] matches;
if(regexp != null && regexp.global) {
matches = re.getAllMatches(s);