src/jdk/nashorn/internal/runtime/regexp/joni/SearchAlgorithm.java

Print this page




 151             int targetEnd = regex.exactEnd;
 152 
 153             int s = textEnd;
 154             s -= targetEnd - targetP;
 155 
 156             if (s > textStart) {
 157                 s = textStart;
 158             }
 159 
 160             while (s >= textP) {
 161                 if (lowerCaseMatch(target, targetP, targetEnd, text, s, textEnd)) return s;
 162                 s = EncodingHelper.prevCharHead(adjustText, s);
 163             }
 164             return -1;
 165         }
 166 
 167         private boolean lowerCaseMatch(char[] t, int tP, int tEnd,
 168                                        char[] chars, int p, int end) {
 169 
 170             while (tP < tEnd) {
 171                 if (t[tP++] != Character.toLowerCase(chars[p++])) return false;
 172             }
 173             return true;
 174         }
 175     }
 176 
 177     public static final SearchAlgorithm BM = new SearchAlgorithm() {
 178 
 179         @Override
 180         public final String getName() {
 181             return "EXACT_BM";
 182         }
 183 
 184         @Override
 185         public final int search(Regex regex, char[] text, int textP, int textEnd, int textRange) {
 186             char[] target = regex.exact;
 187             int targetP = regex.exactP;
 188             int targetEnd = regex.exactEnd;
 189 
 190             int end = textRange + (targetEnd - targetP) - 1;
 191             if (end > textEnd) end = textEnd;




 151             int targetEnd = regex.exactEnd;
 152 
 153             int s = textEnd;
 154             s -= targetEnd - targetP;
 155 
 156             if (s > textStart) {
 157                 s = textStart;
 158             }
 159 
 160             while (s >= textP) {
 161                 if (lowerCaseMatch(target, targetP, targetEnd, text, s, textEnd)) return s;
 162                 s = EncodingHelper.prevCharHead(adjustText, s);
 163             }
 164             return -1;
 165         }
 166 
 167         private boolean lowerCaseMatch(char[] t, int tP, int tEnd,
 168                                        char[] chars, int p, int end) {
 169 
 170             while (tP < tEnd) {
 171                 if (t[tP++] != EncodingHelper.toLowerCase(chars[p++])) return false;
 172             }
 173             return true;
 174         }
 175     }
 176 
 177     public static final SearchAlgorithm BM = new SearchAlgorithm() {
 178 
 179         @Override
 180         public final String getName() {
 181             return "EXACT_BM";
 182         }
 183 
 184         @Override
 185         public final int search(Regex regex, char[] text, int textP, int textEnd, int textRange) {
 186             char[] target = regex.exact;
 187             int targetP = regex.exactP;
 188             int targetEnd = regex.exactEnd;
 189 
 190             int end = textRange + (targetEnd - targetP) - 1;
 191             if (end > textEnd) end = textEnd;