1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $(date) The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
20 *******************************************************************************/
22 // This software is now distributed according to
23 // the Lesser Gnu Public License. Please see
24 // http://www.gnu.org/copyleft/lesser.txt for
26 // -- Happy Computing!
28 package com.stevesoft.pat;
31 * This class makes it easy to create your own patterns and integrate them into
32 * Regex. For more detail, see the example file <a
33 * href="http://javaregex.com/code/deriv2.java.html">deriv2.java</a> or <a
34 * href="http://javaregex.com/code/deriv3.java.html">deriv3.java</a>.
37 public class Validator
39 String argsave = null;
44 * This method does extra checking on a matched section of a String beginning
45 * at position start and ending at end. The idea is that you can do extra
46 * checking with this that you don't know how to do with a standard Regex.
48 * If this method is successful, it returns the location of the end of this
49 * pattern element -- that may be the value end provided or some other value.
50 * A negative value signifies that a match failure.
52 * By default, this method just returns end and thus does nothing.
54 * @see com.stevesoft.pat.Regex#define(java.lang.String,java.lang.String,com.stevesoft.pat.Validator)
56 public int validate(StringLike src, int start, int end)
62 * This method allows you to modify the behavior of this validator by making a
63 * new Validator object. If a Validator named "foo" is defined, then the
64 * pattern "{??foo:bar}" will cause Regex to first get the Validator given to
65 * Regex.define and then to call its arg method with the string "bar". If this
66 * method returns a null (the default) you get the same behavior as the
67 * pattern "{??foo}" would supply.
69 public Validator arg(String s)
75 * For optimization it is helpful, but not necessary, that you define the
76 * minimum number of characters this validator will allow to match. To do this
77 * return new patInt(number) where number is the smallest number of characters
80 public patInt minChars()
86 * For optimization it is helpful, but not necessary, that you define the
87 * maximum number of characters this validator will allow to match. To do this
88 * either return new patInt(number), or new patInf() if an infinite number of
89 * characters may match.
91 public patInt maxChars()