X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSRegexp.java;h=25b890f39c517132160ef665cb94419bb6128a65;hb=37cb1124382eec0585e92f91e9b0bfab579a9264;hp=3353b1dd7ea445f88db8168f3ad846e1e442937b;hpb=7113d47d1ef227732b610026bee8c22b9ada3525;p=org.ibex.js.git diff --git a/src/org/ibex/js/JSRegexp.java b/src/org/ibex/js/JSRegexp.java index 3353b1d..25b890f 100644 --- a/src/org/ibex/js/JSRegexp.java +++ b/src/org/ibex/js/JSRegexp.java @@ -24,10 +24,10 @@ public class JSRegexp extends JS.Immutable { this.pattern = r.pattern; this.flags = r.flags; } else { - String pattern = Script.toString(arg0); + String pattern = JSU.toString(arg0); String sFlags = null; int flags = 0; - if(arg1 != null) sFlags = Script.toString(arg1); + if(arg1 != null) sFlags = JSU.toString(arg1); if(sFlags == null) sFlags = ""; for(int i=0;i= s.length()) { lastIndex = 0; return null; } GnuRegexp.REMatch match = re.getMatch(s,start); @@ -56,27 +56,27 @@ public class JSRegexp extends JS.Immutable { return match == null ? null : matchToExecResult(match,re,s); } case "test": { - String s = Script.toString(args[0]); - if (!global) return Script.B(re.getMatch(s) != null); + String s = JSU.toString(args[0]); + if (!global) return JSU.B(re.getMatch(s) != null); int start = global ? lastIndex : 0; if(start < 0 || start >= s.length()) { lastIndex = 0; return null; } GnuRegexp.REMatch match = re.getMatch(s,start); lastIndex = match != null ? s.length() : match.getEndIndex(); - return Script.B(match != null); + return JSU.B(match != null); } - case "toString": return Script.S(args[0].coerceToString()); + case "toString": return JSU.S(args[0].coerceToString()); //#end break; } case 2: { - //#switch(Script.str(method)) + //#switch(JSU.str(method)) case "stringMatch": return stringMatch(args[0], args[1]); case "stringSearch": return stringSearch(args[0], args[1]); //#end break; } case 3: { - //#switch(Script.str(method)) + //#switch(JSU.str(method)) case "stringReplace": return stringReplace(args[0], args[1], args[2]); //#end break; @@ -86,23 +86,23 @@ public class JSRegexp extends JS.Immutable { } public JS get(JS key) throws JSExn { - //#switch(Script.str(key)) + //#switch(JSU.str(key)) case "exec": return METHOD; case "test": return METHOD; case "toString": return METHOD; - case "lastIndex": return Script.N(lastIndex); + case "lastIndex": return JSU.N(lastIndex); case "source": return pattern; - case "global": return Script.B(global); - case "ignoreCase": return Script.B(flags & GnuRegexp.RE.REG_ICASE); - case "multiline": return Script.B(flags & GnuRegexp.RE.REG_MULTILINE); + case "global": return JSU.B(global); + case "ignoreCase": return JSU.B(flags & GnuRegexp.RE.REG_ICASE); + case "multiline": return JSU.B(flags & GnuRegexp.RE.REG_MULTILINE); //#end return super.get(key); } public void put(JS key, JS value) throws JSExn { - if(Script.isString(key)) { - if(Script.toString(key).equals("lastIndex")) { - lastIndex = Script.toInt(value); + if(JSU.isString(key)) { + if(JSU.toString(key).equals("lastIndex")) { + lastIndex = JSU.toInt(value); return; } } @@ -110,14 +110,15 @@ public class JSRegexp extends JS.Immutable { } private static JS matchToExecResult(GnuRegexp.REMatch match, GnuRegexp.RE re, String s) { + if (match == null) return null; try { JS ret = new JS.Obj(); - ret.put(Script.S("index"), Script.N(match.getStartIndex())); - ret.put(Script.S("input"), Script.S(s)); + ret.put(JSU.S("index"), JSU.N(match.getStartIndex())); + ret.put(JSU.S("input"), JSU.S(s)); int n = re.getNumSubs(); - ret.put(Script.S("length"), Script.N(n+1)); - ret.put(Script.ZERO, Script.S(match.toString())); - for(int i=1;i<=n;i++) ret.put(Script.N(i),Script.S(match.toString(i))); + ret.put(JSU.S("length"), JSU.N(n+1)); + ret.put(JSU.ZERO, JSU.S(match.toString())); + for(int i=1;i<=n;i++) ret.put(JSU.N(i),JSU.S(match.toString(i))); return ret; } catch (JSExn e) { throw new Error("this should never happen"); @@ -137,14 +138,14 @@ public class JSRegexp extends JS.Immutable { private static final JS[] execarg = new JS[1]; static JS stringMatch(JS o, JS arg0) throws JSExn { - String s = Script.toString(o); + String s = JSU.toString(o); GnuRegexp.RE re; JSRegexp regexp = null; if(arg0 instanceof JSRegexp) { regexp = (JSRegexp) arg0; re = regexp.re; } else { - re = newRE(Script.toString(arg0),0); + re = newRE(JSU.toString(arg0),0); } if(regexp == null) { @@ -153,25 +154,25 @@ public class JSRegexp extends JS.Immutable { } try { execarg[0] = o; - if(!regexp.global) return regexp.call(Script.S("exec"), execarg); + if(!regexp.global) return regexp.call(JSU.S("exec"), execarg); } finally { execarg[0] = null; } GnuRegexp.REMatch[] matches = re.getAllMatches(s); JSArray ret = new JSArray(matches.length); - for(int i=0;i 0 ? matches[matches.length-1].getEndIndex() : s.length(); return ret; } static JS stringSearch(JS o, JS arg0) throws JSExn { - String s = Script.toString(o); - GnuRegexp.RE re = arg0 instanceof JSRegexp ? ((JSRegexp)arg0).re : newRE(Script.toString(arg0),0); + String s = JSU.toString(o); + GnuRegexp.RE re = arg0 instanceof JSRegexp ? ((JSRegexp)arg0).re : newRE(JSU.toString(arg0),0); GnuRegexp.REMatch match = re.getMatch(s); - return match == null ? Script.N(-1) : Script.N(match.getStartIndex()); + return match == null ? JSU.N(-1) : JSU.N(match.getStartIndex()); } static JS stringReplace(JS o, JS arg0, JS arg1) throws JSExn { - String s = Script.toString(o); + String s = JSU.toString(o); GnuRegexp.RE re; JSFunction replaceFunc = null; String replaceString = null; @@ -185,7 +186,7 @@ public class JSRegexp extends JS.Immutable { if(arg1 instanceof JSFunction) replaceFunc = (JSFunction) arg1; else - replaceString = Script.toString(arg1); + replaceString = JSU.toString(arg1); GnuRegexp.REMatch[] matches; if(regexp != null && regexp.global) { matches = re.getAllMatches(s); @@ -214,15 +215,15 @@ public class JSRegexp extends JS.Immutable { int n = (regexp == null ? 0 : re.getNumSubs()); int numArgs = 3 + n; JS[] args = new JS[3 + n]; - args[0] = Script.S(match.toString()); + args[0] = JSU.S(match.toString()); args[1] = null; args[2] = null; - for(int j=1;j<=n;j++) args[j] = Script.S(match.toString(j)); - args[args.length - 2] = Script.N(match.getStartIndex()); - args[args.length - 1] = Script.S(s); + for(int j=1;j<=n;j++) args[j] = JSU.S(match.toString(j)); + args[args.length - 2] = JSU.N(match.getStartIndex()); + args[args.length - 1] = JSU.S(s); // note: can't perform pausing operations in here - sb.append(Script.toString(replaceFunc.call(args))); + sb.append(JSU.toString(replaceFunc.call(args))); } else { sb.append(mySubstitute(match,replaceString,s)); @@ -230,7 +231,7 @@ public class JSRegexp extends JS.Immutable { } int end = matches.length == 0 ? 0 : matches[matches.length-1].getEndIndex(); sb.append(sa,end,sa.length-end); - return Script.S(sb.toString()); + return JSU.S(sb.toString()); } private static String mySubstitute(GnuRegexp.REMatch match, String s, String source) { @@ -276,8 +277,8 @@ public class JSRegexp extends JS.Immutable { static JS stringSplit(JS s_, JS arg0, JS arg1, int nargs) throws JSExn { - String s = Script.toString(s_); - int limit = nargs < 2 ? Integer.MAX_VALUE : Script.toInt(arg1); + String s = JSU.toString(s_); + int limit = nargs < 2 ? Integer.MAX_VALUE : JSU.toInt(arg1); if(limit < 0) limit = Integer.MAX_VALUE; if(limit == 0) return new JSArray(0); @@ -291,7 +292,7 @@ public class JSRegexp extends JS.Immutable { regexp = (JSRegexp) arg0; re = regexp.re; } else { - sep = Script.toString(arg0); + sep = JSU.toString(arg0); } // special case this for speed. additionally, the code below doesn't properly handle @@ -299,7 +300,7 @@ public class JSRegexp extends JS.Immutable { if(sep != null && sep.length()==0) { int len = s.length(); for(int i=0;i