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