Perl5Debug.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.apache.oro.text.regex |
![]() |
![]() |
Jakarta ORO |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* $Id: Perl5Debug.java 124053 2005-01-04 01:24:35Z dfs $
*
* Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.oro.text.regex;
/**
* The Perl5Debug class is not intended for general use and should not
* be instantiated, but is provided because some users may find the output
* of its single method to be useful.
* The Perl5Compiler class generates a representation of a
* regular expression identical to that of Perl5 in the abstract, but
* not in terms of actual data structures. The Perl5Debug class allows
* the bytecode program contained by a Perl5Pattern to be printed out for
* comparison with the program generated by Perl5 with the -r option.
*
* @version @version@
* @since 1.0
* @see Perl5Pattern
*/
public final class Perl5Debug {
/**
* A dummy constructor to prevent instantiation of Perl5Debug.
*/
private Perl5Debug() { }
/**
* This method prints to a String the bytecode program contained in a
* Perl5Pattern._ The program byte codes are identical to those
* generated by Perl5 with the -r option, but the offsets are
* different due to the different data structures used. This
* method is useful for diagnosing suspected bugs. The Perl5Compiler
* class is designed to produce regular expression programs identical
* to those produced by Perl5. By comparing the output of this method
* and the output of Perl5 with the -r option on the same regular
* expression, you can determine if Perl5Compiler correctly compiled
* an expression.
* <p>
* @param regexp The Perl5Pattern to print.
* @return A string representation of the bytecode program defining the
* regular expression.
*/
public static String printProgram(Perl5Pattern regexp) {
StringBuffer buffer;
char operator = OpCode._OPEN, prog[];
int offset, next;
prog = regexp._program;
offset = 1;
buffer = new StringBuffer();
while(operator != OpCode._END) {
operator = prog[offset];
buffer.append(offset);
_printOperator(prog, offset, buffer);
next = OpCode._getNext(prog, offset);
offset+=OpCode._operandLength[operator];
buffer.append("(" + next + ")");
offset+=2;
if(operator == OpCode._ANYOF) {
offset += 16;
} else if(operator == OpCode._ANYOFUN || operator == OpCode._NANYOFUN) {
while(prog[offset] != OpCode._END) {
if(prog[offset] == OpCode._RANGE)
offset+=3;
else
offset+=2;
}
++offset;
} else if(operator == OpCode._EXACTLY) {
++offset;
buffer.append(" <");
//while(prog[offset] != '0')
while(prog[offset] != CharStringPointer._END_OF_STRING) {
//while(prog[offset] != 0 &&
// prog[offset] != CharStringPointer._END_OF_STRING) {
buffer.append(prog[offset]);
++offset;
}
buffer.append(">");
++offset;
}
buffer.append('\n');
}
// Can print some other stuff here.
if(regexp._startString != null)
buffer.append("start `" + new String(regexp._startString) + "' ");
if(regexp._startClassOffset != OpCode._NULL_OFFSET) {
buffer.append("stclass `");
_printOperator(prog, regexp._startClassOffset, buffer);
buffer.append("' ");
}
if((regexp._anchor & Perl5Pattern._OPT_ANCH) != 0)
buffer.append("anchored ");
if((regexp._anchor & Perl5Pattern._OPT_SKIP) != 0)
buffer.append("plus ");
if((regexp._anchor & Perl5Pattern._OPT_IMPLICIT) != 0)
buffer.append("implicit ");
if(regexp._mustString != null)
buffer.append("must have \""+ new String(regexp._mustString) +
"\" back " + regexp._back + " ");
buffer.append("minlen " + regexp._minLength + '\n');
return buffer.toString();
}
static void _printOperator(char[] program, int offset, StringBuffer buffer) {
String str = null;
buffer.append(":");
switch(program[offset]) {
case OpCode._BOL : str = "BOL"; break;
case OpCode._MBOL : str = "MBOL"; break;
case OpCode._SBOL : str = "SBOL"; break;
case OpCode._EOL : str = "EOL"; break;
case OpCode._MEOL : str = "MEOL"; break;
case OpCode._ANY : str = "ANY"; break;
case OpCode._SANY : str = "SANY"; break;
case OpCode._ANYOF : str = "ANYOF"; break;
case OpCode._ANYOFUN : str = "ANYOFUN"; break;
case OpCode._NANYOFUN : str = "NANYOFUN"; break;
/*
case OpCode._ANYOF : // debug
buffer.append("ANYOF\n\n");
int foo = OpCode._OPERAND(offset);
char ch;
for(ch=0; ch < 256; ch++) {
if(ch % 16 == 0)
buffer.append(" ");
buffer.append((program[foo + (ch >> 4)] &
(1 << (ch & 0xf))) == 0 ? 0 : 1);
}
buffer.append("\n\n");
break;
*/
case OpCode._BRANCH : str = "BRANCH"; break;
case OpCode._EXACTLY : str = "EXACTLY"; break;
case OpCode._NOTHING : str = "NOTHING"; break;
case OpCode._BACK : str = "BACK"; break;
case OpCode._END : str = "END"; break;
case OpCode._ALNUM : str = "ALNUM"; break;
case OpCode._NALNUM : str = "NALNUM"; break;
case OpCode._BOUND : str = "BOUND"; break;
case OpCode._NBOUND : str = "NBOUND"; break;
case OpCode._SPACE : str = "SPACE"; break;
case OpCode._NSPACE : str = "NSPACE"; break;
case OpCode._DIGIT : str = "DIGIT"; break;
case OpCode._NDIGIT : str = "NDIGIT"; break;
case OpCode._ALPHA : str = "ALPHA"; break;
case OpCode._BLANK : str = "BLANK"; break;
case OpCode._CNTRL : str = "CNTRL"; break;
case OpCode._GRAPH : str = "GRAPH"; break;
case OpCode._LOWER : str = "LOWER"; break;
case OpCode._PRINT : str = "PRINT"; break;
case OpCode._PUNCT : str = "PUNCT"; break;
case OpCode._UPPER : str = "UPPER"; break;
case OpCode._XDIGIT : str = "XDIGIT"; break;
case OpCode._ALNUMC : str = "ALNUMC"; break;
case OpCode._ASCII : str = "ASCII"; break;
case OpCode._CURLY :
buffer.append("CURLY {");
buffer.append((int)OpCode._getArg1(program, offset));
buffer.append(','); buffer.append((int)OpCode._getArg2(program, offset));
buffer.append('}');
break;
case OpCode._CURLYX:
buffer.append("CURLYX {");
buffer.append((int)OpCode._getArg1(program, offset));
buffer.append(','); buffer.append((int)OpCode._getArg2(program, offset));
buffer.append('}');
break;
case OpCode._REF:
buffer.append("REF"); buffer.append((int)OpCode._getArg1(program, offset));
break;
case OpCode._OPEN:
buffer.append("OPEN"); buffer.append((int)OpCode._getArg1(program, offset));
break;
case OpCode._CLOSE:
buffer.append("CLOSE"); buffer.append((int)OpCode._getArg1(program, offset));
break;
case OpCode._STAR : str = "STAR"; break;
case OpCode._PLUS : str = "PLUS"; break;
case OpCode._MINMOD : str = "MINMOD"; break;
case OpCode._GBOL : str = "GBOL"; break;
case OpCode._UNLESSM: str = "UNLESSM"; break;
case OpCode._IFMATCH: str = "IFMATCH"; break;
case OpCode._SUCCEED: str = "SUCCEED"; break;
case OpCode._WHILEM : str = "WHILEM"; break;
default:
buffer.append("Operator is unrecognized. Faulty expression code!");
break;
}
if(str != null)
buffer.append(str);
}
}
The table below shows all metrics for Perl5Debug.java.




