1 28 29 package com.caucho.es; 30 31 import com.caucho.util.IntMap; 32 33 import java.util.Iterator ; 34 import java.util.regex.Pattern ; 35 36 public class ESRegexp extends ESObject { 37 static ESId GLOBAL = ESId.intern("global"); 38 static ESId IGNORE_CASE = ESId.intern("ignoreCase"); 39 static ESId LAST_INDEX = ESId.intern("lastIndex"); 40 static ESId SOURCE = ESId.intern("source"); 41 42 ESString pattern; 43 ESString flags; 44 Pattern _regexp; 45 46 boolean hasSetProps; 47 int lastIndex; 48 ESString lastString; 49 int lastStart; 50 51 ESRegexp(ESString pattern, ESString flags) throws ESException 52 { 53 super("RegExp", getPrototype()); 54 55 this.pattern = pattern; 56 this.flags = flags; 57 lastString = ESString.NULL; 58 59 66 } 67 68 public ESRegexp(String pattern, String flags) throws ESException 69 { 70 super("RegExp", getPrototype()); 71 72 this.pattern = new ESString(pattern); 73 this.flags = new ESString(flags); 74 lastString = ESString.NULL; 75 76 try { 77 _regexp = Pattern.compile(pattern); } catch (Exception e) { 79 throw new ESException("regexp: " + e.getMessage()); 80 } 81 } 82 83 protected ESRegexp() {} 84 85 private static ESBase getPrototype() 86 { 87 Global resin = Global.getGlobalProto(); 88 if (resin == null) 89 return null; 90 else 91 return resin.getRegexpProto(); 92 } 93 94 private void setProps() 95 { 96 if (hasSetProps) 97 return; 98 99 int flags = READ_ONLY|DONT_DELETE; 100 hasSetProps = true; 101 102 put(LAST_INDEX, ESNumber.create(lastIndex), DONT_DELETE); 106 put(SOURCE, pattern, flags); 107 } 108 109 int getLastIndex() throws Throwable 110 { 111 if (! hasSetProps) 112 return lastIndex; 113 else 114 return getProperty(LAST_INDEX).toInt32(); 115 } 116 117 void setLastIndex(int index) 118 { 119 lastIndex = index; 120 hasSetProps = false; 121 } 122 123 public ESBase getProperty(ESString key) throws Throwable 124 { 125 if (! hasSetProps) 126 setProps(); 127 128 return super.getProperty(key); 129 } 130 131 public void setProperty(ESString key, ESBase value) throws Throwable 132 { 133 if (! hasSetProps) 134 setProps(); 135 136 super.setProperty(key, value); 137 } 138 139 public ESBase delete(ESString key) throws Throwable 140 { 141 if (! hasSetProps) 142 setProps(); 143 144 return super.delete(key); 145 } 146 147 public Iterator keys() throws ESException 148 { 149 if (! hasSetProps) 150 setProps(); 151 152 return super.keys(); 153 } 154 155 public ESString toSource(IntMap map, boolean isLoopPass) throws Throwable 156 { 157 if (isLoopPass) 158 return null; 159 else 160 return toStr(); 161 } 162 163 void compile(ESString pattern, ESString flags) throws ESException 164 { 165 if (! this.pattern.equals(pattern) || ! this.flags.equals(flags)) { 166 this.pattern = pattern; 167 this.flags = flags; 168 169 try { 170 } catch (Exception e) { 173 throw new ESException("regexp: " + e); 174 } 175 } 176 177 lastIndex = 0; 178 hasSetProps = false; 179 } 180 181 boolean exec(ESString string, boolean useGlobal) throws Throwable 182 { 183 return false; 184 185 208 } 209 210 public Object toJavaObject() 211 { 212 return null; 215 } 216 217 boolean exec(ESString string) throws Throwable 218 { 219 return false; 220 } 223 224 public ESBase call(Call call, int length) throws Throwable 225 { 226 call.setThis(this); 227 228 return NativeRegexp.exec(call, length); 229 } 230 231 protected ESObject dup() { return new ESRegexp(); } 232 233 protected void copy(Object newObj) 234 { 235 ESRegexp newRegexp = (ESRegexp) newObj; 236 237 super.copy(newObj); 238 239 newRegexp.pattern = pattern; 240 newRegexp.flags = flags; 241 newRegexp.lastString = lastString; 242 243 try { 245 } catch (Exception e) { 248 } 249 } 250 } 251 | Popular Tags |