X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSRegexp.java;h=fb9e67d9de2abe00679305e929a5321a9b4fc4f5;hb=a9010e65b3e6bcd993faf55ce8f05d73c20ddff0;hp=da22d2e22ebd7af4be52a18485a1c1baae25c8b1;hpb=b1fa73c17b31f268fca5695d0876d7314fbacce3;p=org.ibex.js.git diff --git a/src/org/ibex/js/JSRegexp.java b/src/org/ibex/js/JSRegexp.java index da22d2e..fb9e67d 100644 --- a/src/org/ibex/js/JSRegexp.java +++ b/src/org/ibex/js/JSRegexp.java @@ -1,12 +1,10 @@ // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] package org.ibex.js; -import gnu.regexp.*; - /** A JavaScript regular expression object */ public class JSRegexp extends JS { private boolean global; - private RE re; + private GnuRegexp.RE re; private int lastIndex; public JSRegexp(Object arg0, Object arg1) throws JSExn { @@ -23,8 +21,8 @@ public class JSRegexp extends JS { if(sFlags == null) sFlags = ""; for(int i=0;i= s.length()) { lastIndex = 0; return null; } - REMatch match = re.getMatch(s,start); + GnuRegexp.REMatch match = re.getMatch(s,start); if(global) lastIndex = match == null ? s.length() : match.getEndIndex(); return match == null ? null : matchToExecResult(match,re,s); } @@ -54,7 +52,7 @@ public class JSRegexp extends JS { if (!global) return B(re.getMatch(s) != null); int start = global ? lastIndex : 0; if(start < 0 || start >= s.length()) { lastIndex = 0; return null; } - REMatch match = re.getMatch(s,start); + GnuRegexp.REMatch match = re.getMatch(s,start); lastIndex = match != null ? s.length() : match.getEndIndex(); return B(match != null); } @@ -89,7 +87,7 @@ public class JSRegexp extends JS { super.put(key,value); } - private static Object matchToExecResult(REMatch match, RE re, String s) { + private static Object matchToExecResult(GnuRegexp.REMatch match, GnuRegexp.RE re, String s) { try { JS ret = new JS(); ret.put("index", N(match.getStartIndex())); @@ -121,7 +119,7 @@ public class JSRegexp extends JS { public static Object stringMatch(Object o, Object arg0) throws JSExn { String s = o.toString(); - RE re; + GnuRegexp.RE re; JSRegexp regexp = null; if(arg0 instanceof JSRegexp) { regexp = (JSRegexp) arg0; @@ -131,13 +129,13 @@ public class JSRegexp extends JS { } if(regexp == null) { - REMatch match = re.getMatch(s); + GnuRegexp.REMatch match = re.getMatch(s); return matchToExecResult(match,re,s); } if(!regexp.global) return regexp.callMethod("exec", s, null, null, null, 1); JSArray ret = new JSArray(); - REMatch[] matches = re.getAllMatches(s); + GnuRegexp.REMatch[] matches = re.getAllMatches(s); for(int i=0;i 0 ? matches[matches.length-1].getEndIndex() : s.length(); return ret; @@ -145,14 +143,14 @@ public class JSRegexp extends JS { public static Object stringSearch(Object o, Object arg0) throws JSExn { String s = o.toString(); - RE re = arg0 instanceof JSRegexp ? ((JSRegexp)arg0).re : newRE(arg0.toString(),0); - REMatch match = re.getMatch(s); + GnuRegexp.RE re = arg0 instanceof JSRegexp ? ((JSRegexp)arg0).re : newRE(arg0.toString(),0); + GnuRegexp.REMatch match = re.getMatch(s); return match == null ? N(-1) : N(match.getStartIndex()); } public static Object stringReplace(Object o, Object arg0, Object arg1) throws JSExn { String s = o.toString(); - RE re; + GnuRegexp.RE re; JSFunction replaceFunc = null; String replaceString = null; JSRegexp regexp = null; @@ -166,7 +164,7 @@ public class JSRegexp extends JS { replaceFunc = (JSFunction) arg1; else replaceString = JS.toString(arg1.toString()); - REMatch[] matches; + GnuRegexp.REMatch[] matches; if(regexp != null && regexp.global) { matches = re.getAllMatches(s); if(regexp != null) { @@ -176,18 +174,18 @@ public class JSRegexp extends JS { regexp.lastIndex = s.length(); } } else { - REMatch match = re.getMatch(s); + GnuRegexp.REMatch match = re.getMatch(s); if(match != null) - matches = new REMatch[]{ match }; + matches = new GnuRegexp.REMatch[]{ match }; else - matches = new REMatch[0]; + matches = new GnuRegexp.REMatch[0]; } StringBuffer sb = new StringBuffer(s.length()); int pos = 0; char[] sa = s.toCharArray(); for(int i=0;i