2 // This software is now distributed according to
\r
3 // the Lesser Gnu Public License. Please see
\r
4 // http://www.gnu.org/copyleft/lesser.txt for
\r
6 // -- Happy Computing!
\r
8 package com.stevesoft.pat;
\r
9 import java.util.Hashtable;
\r
11 /** This class implements the (?@<>) syntax that matches
\r
12 a balanced parenthesis. Not in perl 5. */
\r
13 class Group extends Pattern {
\r
15 Group(char opi,char cli) {
\r
19 public int matchInternal(int pos,Pthings pt) {
\r
21 if(pos < pt.src.length())
\r
22 if(!Masked(pos,pt) && pt.src.charAt(pos) != op)
\r
24 for(i=pos+1;i<pt.src.length();i++) {
\r
25 char c = pt.src.charAt(i);
\r
26 boolean b = !Masked(i,pt);
\r
30 if(b && c == cl) count--;
\r
31 if(count == 0) return nextMatch(i+1,pt);
\r
32 if(b && c == op) count++;
\r
37 public String toString() {
\r
38 return "(?@"+op+cl+")"+nextString();
\r
40 public patInt minChars() { return new patInt(2); }
\r
41 Pattern clone1(Hashtable h) { return new Group(op,cl); }
\r