1 64 65 package com.jcorporate.expresso.ext.regexp; 66 67 123 124 125 137 public class REProgram { 138 static final int OPT_HASBACKREFS = 1; 139 char[] instruction; int lenInstruction; char[] prefix; int flags; 144 149 public REProgram(char[] instruction) { 150 this(instruction, instruction.length); 151 } 152 153 159 public REProgram(char[] instruction, int lenInstruction) { 160 setInstructions(instruction, lenInstruction); 161 } 162 163 170 public char[] getInstructions() { 171 172 if (lenInstruction != 0) { 174 175 char[] ret = new char[lenInstruction]; 177 System.arraycopy(instruction, 0, ret, 0, lenInstruction); 178 179 return ret; 180 } 181 182 return null; 183 } 184 185 196 public void setInstructions(char[] instruction, int lenInstruction) { 197 198 this.instruction = instruction; 200 this.lenInstruction = lenInstruction; 201 202 flags = 0; 204 prefix = null; 205 206 if (instruction != null && lenInstruction != 0) { 208 209 if (lenInstruction >= RE.nodeSize && 211 instruction[0 + RE.offsetOpcode] == RE.OP_BRANCH) { 212 213 int next = instruction[0 + RE.offsetNext]; 215 216 if (instruction[next + RE.offsetOpcode] == RE.OP_END) { 217 218 if (lenInstruction >= (RE.nodeSize * 2) && 220 instruction[RE.nodeSize + RE.offsetOpcode] == RE.OP_ATOM) { 221 222 int lenAtom = instruction[RE.nodeSize + 224 RE.offsetOpdata]; 225 prefix = new char[lenAtom]; 226 System.arraycopy(instruction, RE.nodeSize * 2, prefix, 227 0, lenAtom); 228 } 229 } 230 } 231 BackrefScanLoop: 232 233 for (int i = 0; i < lenInstruction; i += RE.nodeSize) { 235 switch (instruction[i + RE.offsetOpcode]) { 236 case RE.OP_ANYOF: 237 i += (instruction[i + RE.offsetOpdata] * 2); 238 break; 239 240 case RE.OP_ATOM: 241 i += instruction[i + RE.offsetOpdata]; 242 break; 243 244 case RE.OP_BACKREF: 245 flags |= OPT_HASBACKREFS; 246 break BackrefScanLoop; 247 } 248 } 249 } 250 } 251 } | Popular Tags |