1 package org.apache.regexp; 2 3 59 60 import java.io.Serializable ; 61 62 74 public class REProgram implements Serializable 75 { 76 static final int OPT_HASBACKREFS = 1; 77 78 char[] instruction; int lenInstruction; char[] prefix; int flags; int maxParens = -1; 83 84 88 public REProgram(char[] instruction) 89 { 90 this(instruction, instruction.length); 91 } 92 93 98 public REProgram(int parens, char[] instruction) 99 { 100 this(instruction, instruction.length); 101 this.maxParens = parens; 102 } 103 104 109 public REProgram(char[] instruction, int lenInstruction) 110 { 111 setInstructions(instruction, lenInstruction); 112 } 113 114 120 public char[] getInstructions() 121 { 122 if (lenInstruction != 0) 124 { 125 char[] ret = new char[lenInstruction]; 127 System.arraycopy(instruction, 0, ret, 0, lenInstruction); 128 return ret; 129 } 130 return null; 131 } 132 133 143 public void setInstructions(char[] instruction, int lenInstruction) 144 { 145 this.instruction = instruction; 147 this.lenInstruction = lenInstruction; 148 149 flags = 0; 151 prefix = null; 152 153 if (instruction != null && lenInstruction != 0) 155 { 156 if (lenInstruction >= RE.nodeSize && instruction[0 + RE.offsetOpcode] == RE.OP_BRANCH) 158 { 159 int next = instruction[0 + RE.offsetNext]; 161 if (instruction[next + RE.offsetOpcode] == RE.OP_END) 162 { 163 if (lenInstruction >= (RE.nodeSize * 2) && instruction[RE.nodeSize + RE.offsetOpcode] == RE.OP_ATOM) 165 { 166 int lenAtom = instruction[RE.nodeSize + RE.offsetOpdata]; 168 prefix = new char[lenAtom]; 169 System.arraycopy(instruction, RE.nodeSize * 2, prefix, 0, lenAtom); 170 } 171 } 172 } 173 174 BackrefScanLoop: 175 176 for (int i = 0; i < lenInstruction; i += RE.nodeSize) 178 { 179 switch (instruction[i + RE.offsetOpcode]) 180 { 181 case RE.OP_ANYOF: 182 i += (instruction[i + RE.offsetOpdata] * 2); 183 break; 184 185 case RE.OP_ATOM: 186 i += instruction[i + RE.offsetOpdata]; 187 break; 188 189 case RE.OP_BACKREF: 190 flags |= OPT_HASBACKREFS; 191 break BackrefScanLoop; 192 } 193 } 194 } 195 } 196 } 197 | Popular Tags |