// // This software is now distributed according to // the Lesser Gnu Public License. Please see // http://www.gnu.org/copyleft/lesser.txt for // the details. // -- Happy Computing! // package com.stevesoft.pat; /** This class provides a method for parsing the "s/.../.../" constructs of Regex.perlCode. @see Regex#perlCode */ class parsePerl { final static char close(char c) { // This switch statement does not behave // properly when compiled with jdk1.1.5 // and the -O flag. /* switch(c) { case '[': return ']'; case '(': return ')'; case '{': return '}'; } return c;*/ if(c == '<') return '>'; if(c == '[') return ']'; if(c == '(') return ')'; if(c == '{') return '}'; return c; } final public static String codify(String s,boolean keepbs) { return codify(s,0,s.length(),keepbs); } final public static String codify(String s,int i0,int iN,boolean keepbs) { StringBuffer sb = new StringBuffer(); boolean ucmode = false, lcmode = false, litmode = false; boolean uc1 = false, lc1 = false; boolean modified = false; for(int i=i0;i= 'a' && c <= 'z') return false; if(c >= 'A' && c <= 'Z') return false; if(c >= '0' && c <= '9') return false; if(c == '_') return false; return true; } final static Regex parse(String s) { boolean igncase = false, optim = false, gFlag = false; boolean sFlag = false, mFlag = false, xFlag = false; StringBuffer s1 = new StringBuffer(); StringBuffer s2 = new StringBuffer(); int i=0,count=0; char mode,delim='/',cdelim='/'; if(s.length() >= 3 && s.charAt(0)=='s') { mode = 's'; delim = s.charAt(1); cdelim = close(delim); i=2; } else if(s.length() >= 2 && s.charAt(0)=='m') { mode = 'm'; delim = s.charAt(1); cdelim = close(delim); i=2; } else if(s.length() >= 1 && s.charAt(0)=='/') { mode = 'm'; i=1; } else { try { RegSyntaxError.endItAll( "Regex.perlCode should be of the "+ "form s/// or m// or //"); } catch(RegSyntax rs) {} return null; } for(;i=s.length()) { try { RegSyntaxError.endItAll(""+mode+delim+" needs "+cdelim); } catch(RegSyntax rs) {} return null; } cdelim = close(delim = s.charAt(i)); i++; } count=0; if(mode=='s') { for(;i