2 // This software is now distributed according to
3 // the Lesser Gnu Public License. Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
8 package com.stevesoft.pat;
11 * This class makes it easy to create your own patterns and integrate them into
12 * Regex. For more detail, see the example file <a
13 * href="http://javaregex.com/code/deriv2.java.html">deriv2.java</a> or <a
14 * href="http://javaregex.com/code/deriv3.java.html">deriv3.java</a>.
17 public class Validator
19 String argsave = null;
24 * This method does extra checking on a matched section of a String beginning
25 * at position start and ending at end. The idea is that you can do extra
26 * checking with this that you don't know how to do with a standard Regex.
28 * If this method is successful, it returns the location of the end of this
29 * pattern element -- that may be the value end provided or some other value.
30 * A negative value signifies that a match failure.
32 * By default, this method just returns end and thus does nothing.
34 * @see com.stevesoft.pat.Regex#define(java.lang.String,java.lang.String,com.stevesoft.pat.Validator)
36 public int validate(StringLike src, int start, int end)
42 * This method allows you to modify the behavior of this validator by making a
43 * new Validator object. If a Validator named "foo" is defined, then the
44 * pattern "{??foo:bar}" will cause Regex to first get the Validator given to
45 * Regex.define and then to call its arg method with the string "bar". If this
46 * method returns a null (the default) you get the same behavior as the
47 * pattern "{??foo}" would supply.
49 public Validator arg(String s)
55 * For optimization it is helpful, but not necessary, that you define the
56 * minimum number of characters this validator will allow to match. To do this
57 * return new patInt(number) where number is the smallest number of characters
60 public patInt minChars()
66 * For optimization it is helpful, but not necessary, that you define the
67 * maximum number of characters this validator will allow to match. To do this
68 * either return new patInt(number), or new patInf() if an infinite number of
69 * characters may match.
71 public patInt maxChars()