Initial import
[jpf-core.git] / src / classes / java / util / regex / Matcher.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18
19 package java.util.regex;
20
21 /**
22  * model of a regular expression matcher, to save memory and execution time
23  */
24 public class Matcher {
25
26   // this is the same trick like java.text.Format - avoiding a native
27   // memory leak by means of overwriting a JPF state tracked index value
28   // (well, it's still a leak since it never gets recycled unless we add a
29   // finalizer, but it should be much less serious)
30   static int nInstances;
31   private int id = nInstances++; // just for peer implementation purposes 
32   
33   Pattern pattern;
34   String input;    // that's an approximation (don't use CharSequence on the native side)
35   
36   Matcher() {
37   }
38   
39   Matcher (Pattern pattern, CharSequence inp){
40     this.pattern = pattern;
41     this.input = inp.toString();
42     
43     register();
44   }
45   
46   public Pattern pattern() {
47     return pattern;
48   }
49   
50   native void register();
51   
52   public native Matcher reset();
53   
54   public String group() {
55     return group(0);
56   }
57   
58   public native String group(int group);
59   
60   public native int groupCount();
61
62   public Matcher reset(CharSequence inp) {
63     this.input = inp.toString();
64     return reset();
65   }
66
67   public native boolean matches();
68   
69   public native boolean find();
70   
71   public native boolean lookingAt();
72   
73   public int start() {
74     return start(0);
75   }
76   
77   public native int start(int group);
78   
79   public int end() {
80     return end(0);
81   }
82   
83   public native int end(int group);
84
85   public native boolean hasTransparentBounds();
86
87   public native Matcher useTransparentBounds(boolean b);
88
89   public native boolean hasAnchoringBounds();
90
91   public native Matcher useAnchoringBounds(boolean b);
92
93   public native int regionStart();
94
95   public native int regionEnd();
96
97   public native Matcher region(int start, int end);
98
99   public static native String quoteReplacement(String abc);
100
101   public native String replaceAll(String replacement);
102
103   public native String replaceFirst(String replacement);
104
105   @Override
106   public native String toString();
107
108   public native boolean hitEnd();
109
110   public native boolean requireEnd();
111
112   // TODO public native MatchResult toMatchResult();
113   // TODO public native StringBuffer appendTail(StringBuffer sb);
114   // TODO public native Matcher appendReplacement(StringBuffer sb, String replacement);
115 }