1 Clazz.declarePackage("java.util.regex");
\r
2 Clazz.load(["java.util.regex.MatchResult"],"java.util.regex.Matcher",["java.lang.IllegalArgumentException","$.IndexOutOfBoundsException","$.NullPointerException","$.StringBuffer"],function(){
\r
3 c$=Clazz.decorateAsClass(function(){
\r
9 this.replacement=null;
\r
10 this.processedRepl=null;
\r
11 this.replacementParts=null;
\r
13 Clazz.instantialize(this,arguments);
\r
14 },java.util.regex,"Matcher",null,java.util.regex.MatchResult);
\r
15 Clazz.defineMethod(c$,"appendReplacement",
\r
16 function(sb,replacement){
\r
17 this.processedRepl=this.processReplacement(replacement);
\r
18 sb.append(this.string.subSequence(this.appendPos,this.start()));
\r
19 sb.append(this.processedRepl);
\r
20 this.appendPos=this.end();
\r
22 },"StringBuffer,~S");
\r
23 Clazz.defineMethod(c$,"processReplacement",
\r
24 ($fz=function(replacement){
\r
25 if(this.replacement!=null&&this.replacement.equals(replacement)){
\r
26 if(this.replacementParts==null){
\r
27 return this.processedRepl;
\r
29 var sb=new StringBuffer();
\r
30 for(var i=0;i<this.replacementParts.length;i++){
\r
31 sb.append(this.replacementParts[i]);
\r
33 return sb.toString();
\r
35 this.replacement=replacement;
\r
36 var repl=replacement.toCharArray();
\r
37 var res=new StringBuffer();
\r
38 this.replacementParts=null;
\r
40 var replacementPos=0;
\r
41 var nextBackSlashed=false;
\r
42 while(index<repl.length){
\r
43 if((repl[index]).charCodeAt(0)==('\\').charCodeAt(0)&&!nextBackSlashed){
\r
44 nextBackSlashed=true;
\r
46 }if(nextBackSlashed){
\r
47 res.append(repl[index]);
\r
48 nextBackSlashed=false;
\r
50 if((repl[index]).charCodeAt(0)==('$').charCodeAt(0)){
\r
51 if(this.replacementParts==null){
\r
52 this.replacementParts=new Array(0);
\r
54 var gr=Integer.parseInt(String.instantialize(repl,++index,1));
\r
55 if(replacementPos!=res.length()){
\r
56 this.replacementParts[this.replacementParts.length]=res.subSequence(replacementPos,res.length());
\r
57 replacementPos=res.length();
\r
58 }this.replacementParts[this.replacementParts.length]=((Clazz.isClassDefined("java.util.regex.Matcher$1")?0:java.util.regex.Matcher.$Matcher$1$()),Clazz.innerTypeInstance(java.util.regex.Matcher$1,this,null));
\r
59 var group=this.group(gr);
\r
60 replacementPos+=group.length;
\r
63 if(Clazz.instanceOf(e$$,IndexOutOfBoundsException)){
\r
68 }else if(Clazz.instanceOf(e$$,Exception)){
\r
71 throw new IllegalArgumentException("Illegal regular expression format");
\r
78 res.append(repl[index]);
\r
81 if(this.replacementParts!=null&&replacementPos!=res.length()){
\r
82 this.replacementParts[this.replacementParts.length]=res.subSequence(replacementPos,res.length());
\r
83 }return res.toString();
\r
84 }},$fz.isPrivate=true,$fz),"~S");
\r
85 Clazz.defineMethod(c$,"reset",
\r
86 function(newSequence){
\r
87 if(newSequence==null){
\r
88 throw new NullPointerException("Empty new sequence!");
\r
89 }this.string=newSequence;
\r
90 return this.reset();
\r
92 Clazz.defineMethod(c$,"reset",
\r
95 this.rightBound=this.string.length();
\r
97 this.replacement=null;
\r
99 var flags=""+(this.pat.regexp.ignoreCase?"i":"")
\r
100 +(this.pat.regexp.global?"g":"")
\r
101 +(this.pat.regexp.multiline?"m":"");
\r
102 this.pat.regexp=new RegExp(this.pat.regexp.source,flags);
\r
105 Clazz.defineMethod(c$,"region",
\r
106 function(leftBound,rightBound){
\r
107 if(leftBound>rightBound||leftBound<0||rightBound<0||leftBound>this.string.length()||rightBound>this.string.length()){
\r
108 throw new IndexOutOfBoundsException(leftBound+" is out of bound of "+rightBound);
\r
109 }this.leftBound=leftBound;
\r
110 this.rightBound=rightBound;
\r
113 this.replacement=null;
\r
116 Clazz.defineMethod(c$,"appendTail",
\r
118 return sb.append(this.string.subSequence(this.appendPos,this.string.length()));
\r
120 Clazz.defineMethod(c$,"replaceFirst",
\r
121 function(replacement){
\r
124 var sb=new StringBuffer();
\r
125 this.appendReplacement(sb,replacement);
\r
126 return this.appendTail(sb).toString();
\r
127 }return this.string.toString();
\r
129 Clazz.defineMethod(c$,"replaceAll",
\r
130 function(replacement){
\r
131 var sb=new StringBuffer();
\r
133 while(this.find()){
\r
134 this.appendReplacement(sb,replacement);
\r
136 return this.appendTail(sb).toString();
\r
138 Clazz.defineMethod(c$,"pattern",
\r
142 Clazz.defineMethod(c$,"group",
\r
143 function(groupIndex){
\r
144 if(this.results==null||groupIndex<0||groupIndex>this.results.length){
\r
146 }return this.results[groupIndex];
\r
148 Clazz.defineMethod(c$,"group",
\r
150 return this.group(0);
\r
152 Clazz.defineMethod(c$,"find",
\r
153 function(startIndex){
\r
154 var stringLength=this.string.length();
\r
155 if(startIndex<0||startIndex>stringLength)throw new IndexOutOfBoundsException("Out of bound "+startIndex);
\r
156 startIndex=this.findAt(startIndex);
\r
159 Clazz.defineMethod(c$,"findAt",
\r
160 ($fz=function(startIndex){
\r
162 },$fz.isPrivate=true,$fz),"~N");
\r
163 Clazz.defineMethod(c$,"find",
\r
166 this.results=this.pat.regexp.exec(this.string.subSequence(this.leftBound,this.rightBound));
\r
167 }return(this.results!=null);
\r
169 Clazz.defineMethod(c$,"start",
\r
170 function(groupIndex){
\r
171 var beginningIndex=0;
\r
173 beginningIndex=this.pat.regexp.lastIndex;
\r
174 }beginningIndex-=this.results[0].length;
\r
175 return beginningIndex;
\r
177 Clazz.defineMethod(c$,"end",
\r
178 function(groupIndex){
\r
180 return this.pat.regexp.lastIndex;
\r
183 Clazz.defineMethod(c$,"matches",
\r
185 return this.find();
\r
187 c$.quoteReplacement=Clazz.defineMethod(c$,"quoteReplacement",
\r
189 if(string.indexOf('\\') < 0 && string.indexOf ('$')<0)return string;
\r
190 var res=new StringBuffer(string.length*2);
\r
192 var len=string.length;
\r
193 for(var i=0;i<len;i++){
\r
194 switch(ch=string.charAt(i)){
\r
207 return res.toString();
\r
209 Clazz.defineMethod(c$,"lookingAt",
\r
213 Clazz.defineMethod(c$,"start",
\r
215 return this.start(0);
\r
217 Clazz.overrideMethod(c$,"groupCount",
\r
219 return this.results==null?0:this.results.length;
\r
221 Clazz.defineMethod(c$,"end",
\r
223 return this.end(0);
\r
225 Clazz.defineMethod(c$,"toMatchResult",
\r
229 Clazz.defineMethod(c$,"useAnchoringBounds",
\r
233 Clazz.defineMethod(c$,"hasAnchoringBounds",
\r
237 Clazz.defineMethod(c$,"useTransparentBounds",
\r
241 Clazz.defineMethod(c$,"hasTransparentBounds",
\r
245 Clazz.defineMethod(c$,"regionStart",
\r
247 return this.leftBound;
\r
249 Clazz.defineMethod(c$,"regionEnd",
\r
251 return this.rightBound;
\r
253 Clazz.defineMethod(c$,"requireEnd",
\r
257 Clazz.defineMethod(c$,"hitEnd",
\r
261 Clazz.defineMethod(c$,"usePattern",
\r
264 throw new IllegalArgumentException("Empty pattern!");
\r
268 },"java.util.regex.Pattern");
\r
269 Clazz.makeConstructor(c$,
\r
274 this.rightBound=this.string.toString().length;
\r
275 },"java.util.regex.Pattern,CharSequence");
\r
276 c$.$Matcher$1$=function(){
\r
277 Clazz.pu$h(self.c$);
\r
278 c$=Clazz.decorateAsClass(function(){
\r
279 Clazz.prepareCallback(this,arguments);
\r
281 Clazz.instantialize(this,arguments);
\r
282 },java.util.regex,"Matcher$1");
\r
283 Clazz.prepareFields(c$,function(){
\r
286 Clazz.overrideMethod(c$,"toString",
\r
288 return this.b$["java.util.regex.Matcher"].group(this.grN);
\r
292 Clazz.defineStatics(c$,
\r