1 package com.sun.org.apache.regexp.internal; 2 3 59 60 import com.sun.org.apache.regexp.internal.RE; 61 import java.util.Hashtable ; 62 63 75 public class REProgram 76 { 77 static final int OPT_HASBACKREFS = 1; 78 79 char[] instruction; int lenInstruction; char[] prefix; int flags; 84 88 public REProgram(char[] instruction) 89 { 90 this(instruction, instruction.length); 91 } 92 93 98 public REProgram(char[] instruction, int lenInstruction) 99 { 100 setInstructions(instruction, lenInstruction); 101 } 102 103 109 public char[] getInstructions() 110 { 111 if (lenInstruction != 0) 113 { 114 char[] ret = new char[lenInstruction]; 116 System.arraycopy(instruction, 0, ret, 0, lenInstruction); 117 return ret; 118 } 119 return null; 120 } 121 122 132 public void setInstructions(char[] instruction, int lenInstruction) 133 { 134 this.instruction = instruction; 136 this.lenInstruction = lenInstruction; 137 138 flags = 0; 140 prefix = null; 141 142 if (instruction != null && lenInstruction != 0) 144 { 145 if (lenInstruction >= RE.nodeSize && instruction[0 + RE.offsetOpcode] == RE.OP_BRANCH) 147 { 148 int next = instruction[0 + RE.offsetNext]; 150 if (instruction[next + RE.offsetOpcode] == RE.OP_END) 151 { 152 if (lenInstruction >= (RE.nodeSize * 2) && instruction[RE.nodeSize + RE.offsetOpcode] == RE.OP_ATOM) 154 { 155 int lenAtom = instruction[RE.nodeSize + RE.offsetOpdata]; 157 prefix = new char[lenAtom]; 158 System.arraycopy(instruction, RE.nodeSize * 2, prefix, 0, lenAtom); 159 } 160 } 161 } 162 163 BackrefScanLoop: 164 165 for (int i = 0; i < lenInstruction; i += RE.nodeSize) 167 { 168 switch (instruction[i + RE.offsetOpcode]) 169 { 170 case RE.OP_ANYOF: 171 i += (instruction[i + RE.offsetOpdata] * 2); 172 break; 173 174 case RE.OP_ATOM: 175 i += instruction[i + RE.offsetOpdata]; 176 break; 177 178 case RE.OP_BACKREF: 179 flags |= OPT_HASBACKREFS; 180 break BackrefScanLoop; 181 } 182 } 183 } 184 } 185 } 186 | Popular Tags |