| 
 |   | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This interface is used by the Regexp class to generate
 the replacement string for each pattern match found in the source
 string.
| Method Summary | |
|  boolean | filter(Regsub rs,
       StringBuffer sb)Given the current state of the match, generate the replacement string. | 
| Method Detail | 
public boolean filter(Regsub rs,
                      StringBuffer sb)
The implementation can use whatever rules it chooses to generate the replacement string. For example, here is an example of a filter that replaces the first 5 occurrences of "%XX" in a string with the ASCII character represented by the hex digits "XX":
 String str = ...;
 Regexp re = new Regexp("%[a-fA-F0-9][a-fA-F0-9]");
 Regexp.Filter rf = new Regexp.Filter() {
     int count = 5;
     public boolean filter(Regsub rs, StringBuffer sb) {
         String match = rs.matched();
         int hi = Character.digit(match.charAt(1), 16);
         int lo = Character.digit(match.charAt(2), 16);
         sb.append((char) ((hi << 4) | lo));
         return (--count > 0);
     }
 }
 String result = re.sub(str, rf);
 
rs - Regsub containing the state of the current
	    match.sb - The string buffer that this filter should append the
	    generated string to.  This string buffer actually
	    contains the results the calling Regexp has
	    generated up to this point.
false if no further matches should be
	    considered in this string, true to allow
	    Regexp to continue looking for further
	    matches.| 
 | Version 2.1, Generated 12/30/04 Copyright (c) 2001-2004, Sun Microsystems. | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||