1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.ibm.icu4jni.regex; 18 19 public class NativeRegEx { 20 21 /** 22 * Opens (compiles) an ICU regular expression. 23 */ 24 public static native int open(String pattern, int flags); 25 26 /** 27 * Makes a copy of a compiled regular expression. 28 */ 29 public static native int clone(int regex); 30 31 /** 32 * Closes the regular expression, recovering all resources (memory) it was 33 * holding. 34 */ 35 public static native void close(int regex); 36 37 /** 38 * Sets the subject text string upon which the regular expression will look 39 * for matches. 40 */ 41 public static native void setText(int regex, String text); 42 43 /** 44 * Attempts to match the input string, beginning at startIndex, against the 45 * pattern. 46 */ 47 public static native boolean matches(int regex, int startIndex); 48 49 /** 50 * Attempts to match the input string, starting from the specified index, 51 * against the pattern. 52 */ 53 public static native boolean lookingAt(int regex, int startIndex); 54 55 /** 56 * Finds the first matching substring of the input string that matches the 57 * pattern. 58 */ 59 public static native boolean find(int regex, int startIndex); 60 61 /** 62 * Finds the first matching substring of the input string that matches the 63 * pattern. 64 */ 65 public static native boolean findNext(int regex); 66 67 /** 68 * Gets the number of capturing groups in this regular expression's pattern. 69 */ 70 public static native int groupCount(int regex); 71 72 /** 73 * Gets all the group information for the current match of the pattern. 74 */ 75 public static native void startEnd(int regex, int[] startEnd); 76 77 /** 78 * Sets the region of the input to be considered during matching. 79 */ 80 public static native void setRegion(int regex, int start, int end); 81 82 /** 83 * Queries the start of the region of the input to be considered during 84 * matching. 85 */ 86 public static native int regionStart(int regex); 87 88 /** 89 * Queries the end of the region of the input to be considered during 90 * matching. 91 */ 92 public static native int regionEnd(int regex); 93 94 /** 95 * Controls the transparency of the region bounds. 96 */ 97 public static native void useTransparentBounds(int regex, boolean value); 98 99 /** 100 * Queries the transparency of the region bounds. 101 */ 102 public static native boolean hasTransparentBounds(int regex); 103 104 /** 105 * Controls the anchoring property of the region bounds. 106 */ 107 public static native void useAnchoringBounds(int regex, boolean value); 108 109 /** 110 * Queries the anchoring property of the region bounds. 111 */ 112 public static native boolean hasAnchoringBounds(int regex); 113 114 /** 115 * Queries whether we hit the end of the input during the last match. 116 */ 117 public static native boolean hitEnd(int regex); 118 119 /** 120 * Queries whether more input might change a current match, but wouldn't 121 * destroy it. 122 */ 123 public static native boolean requireEnd(int regex); 124 125 /** 126 * Resets the matcher, cause a current match to be lost, and sets the 127 * position at which a subsequent findNext() would start. 128 */ 129 public static native void reset(int regex, int position); 130 } 131