1 28 29 package com.caucho.es; 30 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 34 class ESRegexpWrapper extends NativeWrapper { 35 static ESId INPUT = ESId.intern("input"); 36 static ESId MULTILINE = ESId.intern("multiline"); 37 static ESId LAST_MATCH = ESId.intern("lastMatch"); 38 static ESId LAST_PAREN = ESId.intern("lastParen"); 39 static ESId LEFT_CONTEXT = ESId.intern("leftContext"); 40 static ESId RIGHT_CONTEXT = ESId.intern("rightContext"); 41 static ESId G1 = ESId.intern("$1"); 42 static ESId G2 = ESId.intern("$2"); 43 static ESId G3 = ESId.intern("$3"); 44 static ESId G4 = ESId.intern("$4"); 45 static ESId G5 = ESId.intern("$5"); 46 static ESId G6 = ESId.intern("$6"); 47 static ESId G7 = ESId.intern("$7"); 48 static ESId G8 = ESId.intern("$8"); 49 static ESId G9 = ESId.intern("$9"); 50 51 static HashMap aliases; 52 53 static { 54 aliases = new HashMap (); 55 56 aliases.put(ESId.intern("$_"), INPUT); 57 aliases.put(ESId.intern("$`"), LEFT_CONTEXT); 58 aliases.put(ESId.intern("$'"), RIGHT_CONTEXT); 59 aliases.put(ESId.intern("$&"), LAST_MATCH); 60 aliases.put(ESId.intern("$0"), LAST_MATCH); 61 aliases.put(ESId.intern("$+"), LAST_PAREN); 62 } 63 64 ESRegexp regexp; 65 66 boolean hasSetProps; 67 68 ESRegexpWrapper(Global resin, Native fun, ESRegexp proto) 69 { 70 super(resin, fun, proto, ESThunk.REGEXP_THUNK); 71 72 regexp = proto; 73 hasSetProps = false; 74 75 put(INPUT, ESString.NULL, DONT_DELETE); 76 put(MULTILINE, ESBoolean.FALSE, DONT_DELETE); 77 } 78 79 protected ESRegexpWrapper() 80 { 81 } 82 83 private void setProps() 84 { 85 120 } 121 122 void setRegexp(ESRegexp regexp) 123 { 124 this.regexp = regexp; 125 hasSetProps = false; 126 } 127 128 public ESBase getProperty(ESString key) throws Throwable 129 { 130 if (! hasSetProps) 131 setProps(); 132 133 ESId alias = (ESId) aliases.get(key); 134 return super.getProperty(alias != null ? alias : key); 135 } 136 137 public void setProperty(ESString key, ESBase value) throws Throwable 138 { 139 if (! hasSetProps && regexp != null) 140 setProps(); 141 142 ESId alias = (ESId) aliases.get(key); 143 super.setProperty(alias != null ? alias : key, value); 144 } 145 146 public ESBase delete(ESString key) throws Throwable 147 { 148 if (! hasSetProps) 149 setProps(); 150 151 ESId alias = (ESId) aliases.get(key); 152 return super.delete(alias != null ? alias : key); 153 } 154 155 public Iterator keys() throws ESException 156 { 157 if (! hasSetProps) 158 setProps(); 159 160 return super.keys(); 161 } 162 163 protected ESObject dup() { return new ESRegexpWrapper(); } 164 165 protected void copy(Object obj) 166 { 167 ESRegexpWrapper wrap = (ESRegexpWrapper) obj; 168 169 super.copy(obj); 170 171 hasSetProps = false; 172 } 173 } 174 | Popular Tags |