needed for applet search
[jalview.git] / src / com / stevesoft / pat / Validator.java
1 //\r
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
5 // the details.\r
6 //    -- Happy Computing!\r
7 //\r
8 package com.stevesoft.pat;\r
9 \r
10 /** This class makes it easy to create your own patterns\r
11 and integrate them into Regex.  For more detail, see the\r
12 example file <a href="http://javaregex.com/code/deriv2.java.html">deriv2.java</a> or\r
13 <a href="http://javaregex.com/code/deriv3.java.html">deriv3.java</a>. */\r
14 \r
15 public class Validator {\r
16     String argsave = null;\r
17     String pattern = ".";\r
18     /**\r
19     This method does extra checking on a matched section of\r
20     a String beginning at position start and ending at end.\r
21     The idea is that you can do extra checking with this\r
22     that you don't know how to do with a standard Regex.\r
23 \r
24     If this method is successful, it returns the location\r
25     of the end of this pattern element -- that may be the\r
26     value end provided or some other value.  A negative\r
27     value signifies that a match failure.\r
28     \r
29     By default, this method just returns end and thus\r
30     does nothing.\r
31     @see com.stevesoft.pat.Regex#define(java.lang.String,java.lang.String,com.stevesoft.pat.Validator)\r
32     */\r
33     public int validate(StringLike src,int start,int end) {\r
34         return end;\r
35     }\r
36     /* This method allows you to modify the behavior of this\r
37     validator by making a new Validator object.  If a Validator\r
38     named "foo" is defined, then the pattern "{??foo:bar}" will\r
39     cause Regex to first get the Validator given to Regex.define\r
40     and then to call its arg method with the string "bar".\r
41     If this method returns a null (the default) you get the same\r
42     behavior as the pattern "{??foo}" would supply. */\r
43     public Validator arg(String s) { return null; }\r
44 \r
45     /** For optimization it is helpful, but not necessary, that\r
46     you define the minimum number of characters this validator\r
47     will allow to match.  To do this \r
48     return new patInt(number) where number is the smallest\r
49     number of characters that can match. */\r
50     public patInt minChars() { return new patInt(0); }\r
51 \r
52     /** For optimization it is helpful, but not necessary, that\r
53     you define the maximum number of characters this validator\r
54     will allow to match.  To do this either\r
55     return new patInt(number), or new patInf() if an infinite\r
56     number of characters may match. */\r
57     public patInt maxChars() { return new patInf(); }\r
58 }\r