2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
19 package java.util.regex;
22 * model of a regular expression matcher, to save memory and execution time
24 public class Matcher {
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
34 String input; // that's an approximation (don't use CharSequence on the native side)
39 Matcher (Pattern pattern, CharSequence inp){
40 this.pattern = pattern;
41 this.input = inp.toString();
46 public Pattern pattern() {
50 native void register();
52 public native Matcher reset();
54 public String group() {
58 public native String group(int group);
60 public native int groupCount();
62 public Matcher reset(CharSequence inp) {
63 this.input = inp.toString();
67 public native boolean matches();
69 public native boolean find();
71 public native boolean lookingAt();
77 public native int start(int group);
83 public native int end(int group);
85 public native boolean hasTransparentBounds();
87 public native Matcher useTransparentBounds(boolean b);
89 public native boolean hasAnchoringBounds();
91 public native Matcher useAnchoringBounds(boolean b);
93 public native int regionStart();
95 public native int regionEnd();
97 public native Matcher region(int start, int end);
99 public static native String quoteReplacement(String abc);
101 public native String replaceAll(String replacement);
103 public native String replaceFirst(String replacement);
106 public native String toString();
108 public native boolean hitEnd();
110 public native boolean requireEnd();
112 // TODO public native MatchResult toMatchResult();
113 // TODO public native StringBuffer appendTail(StringBuffer sb);
114 // TODO public native Matcher appendReplacement(StringBuffer sb, String replacement);