needed for applet search
[jalview.git] / src / com / stevesoft / pat / Validator.java
diff --git a/src/com/stevesoft/pat/Validator.java b/src/com/stevesoft/pat/Validator.java
new file mode 100755 (executable)
index 0000000..facd3f7
--- /dev/null
@@ -0,0 +1,58 @@
+//\r
+// This software is now distributed according to\r
+// the Lesser Gnu Public License.  Please see\r
+// http://www.gnu.org/copyleft/lesser.txt for\r
+// the details.\r
+//    -- Happy Computing!\r
+//\r
+package com.stevesoft.pat;\r
+\r
+/** This class makes it easy to create your own patterns\r
+and integrate them into Regex.  For more detail, see the\r
+example file <a href="http://javaregex.com/code/deriv2.java.html">deriv2.java</a> or\r
+<a href="http://javaregex.com/code/deriv3.java.html">deriv3.java</a>. */\r
+\r
+public class Validator {\r
+    String argsave = null;\r
+    String pattern = ".";\r
+    /**\r
+    This method does extra checking on a matched section of\r
+    a String beginning at position start and ending at end.\r
+    The idea is that you can do extra checking with this\r
+    that you don't know how to do with a standard Regex.\r
+\r
+    If this method is successful, it returns the location\r
+    of the end of this pattern element -- that may be the\r
+    value end provided or some other value.  A negative\r
+    value signifies that a match failure.\r
+    \r
+    By default, this method just returns end and thus\r
+    does nothing.\r
+    @see com.stevesoft.pat.Regex#define(java.lang.String,java.lang.String,com.stevesoft.pat.Validator)\r
+    */\r
+    public int validate(StringLike src,int start,int end) {\r
+        return end;\r
+    }\r
+    /* This method allows you to modify the behavior of this\r
+    validator by making a new Validator object.  If a Validator\r
+    named "foo" is defined, then the pattern "{??foo:bar}" will\r
+    cause Regex to first get the Validator given to Regex.define\r
+    and then to call its arg method with the string "bar".\r
+    If this method returns a null (the default) you get the same\r
+    behavior as the pattern "{??foo}" would supply. */\r
+    public Validator arg(String s) { return null; }\r
+\r
+    /** For optimization it is helpful, but not necessary, that\r
+    you define the minimum number of characters this validator\r
+    will allow to match.  To do this \r
+    return new patInt(number) where number is the smallest\r
+    number of characters that can match. */\r
+    public patInt minChars() { return new patInt(0); }\r
+\r
+    /** For optimization it is helpful, but not necessary, that\r
+    you define the maximum number of characters this validator\r
+    will allow to match.  To do this either\r
+    return new patInt(number), or new patInf() if an infinite\r
+    number of characters may match. */\r
+    public patInt maxChars() { return new patInf(); }\r
+}\r