//
package com.stevesoft.pat;
-import java.io.*;
-import java.util.*;
+import jalview.util.MessageManager;
-import com.stevesoft.pat.wrap.*;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.BitSet;
+import java.util.Hashtable;
+
+import com.stevesoft.pat.wrap.StringWrap;
/** Matches a Unicode punctuation character. */
class UnicodePunct extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && Prop.isPunct(s.charAt(from)) ? to : -1;
/** Matches a Unicode white space character. */
class UnicodeWhite extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && Prop.isWhite(s.charAt(from)) ? to : -1;
*/
class NUnicodePunct extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && !Prop.isPunct(s.charAt(from)) ? to : -1;
*/
class NUnicodeWhite extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && !Prop.isWhite(s.charAt(from)) ? to : -1;
/** Matches a Unicode word character: an alphanumeric or underscore. */
class UnicodeW extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
if (from >= s.length())
/** Matches a character that is not a Unicode alphanumeric or underscore. */
class NUnicodeW extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
if (from >= s.length())
return -1;
}
char c = s.charAt(from);
- return !(Prop.isAlphabetic(c) || Prop.isDecimalDigit(c) || c == '_') ? to
+ return !(Prop.isAlphabetic(c) || Prop.isDecimalDigit(c) || c == '_')
+ ? to
: -1;
}
}
/** Matches a Unicode decimal digit. */
class UnicodeDigit extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && Prop.isDecimalDigit(s.charAt(from)) ? to
/** Matches a character that is not a Unicode digit. */
class NUnicodeDigit extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && !Prop.isDecimalDigit(s.charAt(from)) ? to
/** Matches a Unicode math character. */
class UnicodeMath extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && Prop.isMath(s.charAt(from)) ? to : -1;
/** Matches a non-math Unicode character. */
class NUnicodeMath extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && !Prop.isMath(s.charAt(from)) ? to : -1;
/** Matches a Unicode currency symbol. */
class UnicodeCurrency extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && Prop.isCurrency(s.charAt(from)) ? to : -1;
/** Matches a non-currency symbol Unicode character. */
class NUnicodeCurrency extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && !Prop.isCurrency(s.charAt(from)) ? to : -1;
/** Matches a Unicode alphabetic character. */
class UnicodeAlpha extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && Prop.isAlphabetic(s.charAt(from)) ? to : -1;
/** Matches a non-alphabetic Unicode character. */
class NUnicodeAlpha extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && !Prop.isAlphabetic(s.charAt(from)) ? to
/** Matches an upper case Unicode character. */
class UnicodeUpper extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && isUpper(s.charAt(from)) ? to : -1;
/** Matches an upper case Unicode character. */
class UnicodeLower extends UniValidator
{
+ @Override
public int validate(StringLike s, int from, int to)
{
return from < s.length() && isLower(s.charAt(from)) ? to : -1;
*
* <pre>
* \d+
- * </pre>, but note that the sequence
+ * </pre>
+ *
+ * , but note that the sequence
*
* <pre>
* (?e=#)
* small differences as well. I will either make my package conform or note them
* as I become aware of them.
* <p>
- * This package supports additional patterns not in perl5: <center> <table
+ * This package supports additional patterns not in perl5: <center> <table *
* border=1>
* <tr>
* <td>(?@())</td>
* "look behind." It fails if it attempts to move to a position before the
* beginning of the string. "x(?<1)" is equivalent to "(?=x)". The number, 1
* in this example, is the number of characters to move backwards.</td>
- * </table> </center>
+ * </table>
+ * </center>
* </dl>
*
* @author Steven R. Brandt
/** Essentially clones the Regex object */
public Regex(Regex r)
{
- super((RegRes) r);
+ super(r);
dontMatchInQuotes = r.dontMatchInQuotes;
esc = r.esc;
ignoreCase = r.ignoreCase;
* search or matchAt methods.
*
* @exception com.stevesoft.pat.RegSyntax
- * is thrown if a syntax error is encountered in the
- * pattern. For example, "x{3,1}" or "*a" are not valid
- * patterns.
+ * is thrown if a syntax error is encountered in the pattern. For
+ * example, "x{3,1}" or "*a" are not valid patterns.
* @see com.stevesoft.pat.Regex#search
* @see com.stevesoft.pat.Regex#matchAt
*/
* patterns are equal as well as the most recent match. If a Regex is compare
* with a RegRes, only the result of the most recent match is compared.
*/
+ @Override
public boolean equals(Object o)
{
if (o instanceof Regex)
}
/** A clone by any other name would smell as sweet. */
+ @Override
public Object clone()
{
return new Regex(this);
{
pt.lastPos = 0;
}
- if ((s == null ? null : s.unwrap()) != (src == null ? null : s.unwrap()))
+ if ((s == null ? null : s.unwrap()) != (src == null ? null
+ : s.unwrap()))
{
pt.lastPos = 0;
}
{
if (s == null)
{
- throw new NullPointerException("Null String Given to Regex.search");
+ throw new NullPointerException(MessageManager
+ .getString("exception.null_string_given_to_regex_search"));
}
return _search(s, 0, s.length());
}
{
if (sl == null)
{
- throw new NullPointerException(
- "Null StringLike Given to Regex.search");
+ throw new NullPointerException(MessageManager.getString(
+ "exception.null_string_like_given_to_regex_search"));
}
return _search(sl, 0, sl.length());
}
{
if (s == null)
{
- throw new NullPointerException(
- "Null String Given to Regex.reverseSearch");
+ throw new NullPointerException(MessageManager.getString(
+ "exception.null_string_given_to_regex_reverse_search"));
}
return _reverseSearch(s, 0, s.length());
}
{
if (sl == null)
{
- throw new NullPointerException(
- "Null StringLike Given to Regex.reverseSearch");
+ throw new NullPointerException(MessageManager.getString(
+ "exception.null_string_like_given_to_regex_reverse_search"));
}
return _reverseSearch(sl, 0, sl.length());
}
{
if (s == null)
{
- throw new NullPointerException(
- "Null String Given to Regex.searchFrom");
+ throw new NullPointerException(MessageManager.getString(
+ "exception.null_string_like_given_to_regex_search_from"));
}
return _search(s, start, s.length());
}
{
if (s == null)
{
- throw new NullPointerException(
- "Null String Given to Regex.searchFrom");
+ throw new NullPointerException(MessageManager.getString(
+ "exception.null_string_like_given_to_regex_search_from"));
}
return _search(s, start, s.length());
}
{
if (s == null)
{
- throw new NullPointerException(
- "Null String Given to Regex.searchRegion");
+ throw new NullPointerException(MessageManager.getString(
+ "exception.null_string_like_given_to_regex_search_region"));
}
return _search(s, start, end);
}
* if(skipper == null) { for(long i=start;i<=up;i++) { charsMatched_ =
* thePattern.matchAt(s,i,pt); if(charsMatched_ >= 0) { matchFrom_ =
* thePattern.mfrom; marks = pt.marks; gFlagto = matchFrom_+charsMatched_;
- * return didMatch_=true; } } } else { pt.no_check = true; for(long i=start;i<=up;i++) {
- * i = skipper.find(src,i,up); if(i<0) { charsMatched_ = matchFrom_ = -1;
- * return didMatch_ = false; } charsMatched_ = thePattern.matchAt(s,i,pt);
- * if(charsMatched_ >= 0) { matchFrom_ = thePattern.mfrom; marks = pt.marks;
- * gFlagto = matchFrom_+charsMatched_; gFlags = s; return didMatch_=true; }
- * else { i = s.adjustIndex(i); up = s.adjustEnd(i); } } } return
- * didMatch_=false; }
+ * return didMatch_=true; } } } else { pt.no_check = true; for(long
+ * i=start;i<=up;i++) { i = skipper.find(src,i,up); if(i<0) { charsMatched_ =
+ * matchFrom_ = -1; return didMatch_ = false; } charsMatched_ =
+ * thePattern.matchAt(s,i,pt); if(charsMatched_ >= 0) { matchFrom_ =
+ * thePattern.mfrom; marks = pt.marks; gFlagto = matchFrom_+charsMatched_;
+ * gFlags = s; return didMatch_=true; } else { i = s.adjustIndex(i); up =
+ * s.adjustEnd(i); } } } return didMatch_=false; }
*/
boolean _reverseSearch(String s, int start, int end)
{
try
{
- return (Regex) getClass().newInstance();
+ return getClass().getDeclaredConstructor().newInstance();
} catch (InstantiationException ie)
{
return null;
} catch (IllegalAccessException iae)
{
return null;
+ } catch (ReflectiveOperationException roe)
+ {
+ return null;
}
}
* the Pattern.
*
* @exception com.stevesoft.pat.RegSyntax
- * is thrown when a nonsensensical pattern is supplied. For
- * example, a pattern beginning with *.
+ * is thrown when a nonsensensical pattern is supplied. For
+ * example, a pattern beginning with *.
*/
protected void compile1(StrPos sp, Rthings mk) throws RegSyntax
{
{
if (p instanceof Any && p.next == null)
{
- return (Pattern) new DotMulti(lo, hi);
+ return new DotMulti(lo, hi);
}
return RegOpt.safe4fm(p) ? (Pattern) new FastMulti(lo, hi, p)
: (Pattern) new Multi(lo, hi, p);
* representations. Also be prepared to see some strange output if your
* characters are not printable.
*/
+ @Override
public String toString()
{
if (false && thePattern == null)
*
* @see com.stevesoft.pat.FileRegex
*/
+ @Override
public boolean accept(File dir, String s)
{
return search(s);
* optimized() method.
* <p>
* This method will attempt to rewrite your pattern in a way that makes it
- * faster (not all patterns execute at the same speed). In general, "(?: ... )"
- * will be faster than "( ... )" so if you don't need the backreference, you
- * should group using the former pattern.
+ * faster (not all patterns execute at the same speed). In general, "(?: ...
+ * )" will be faster than "( ... )" so if you don't need the backreference,
+ * you should group using the former pattern.
* <p>
* It will also introduce new pattern elements that you can't get to
* otherwise, for example if you have a large table of strings, i.e. the
boolean isHexDigit(StrPos sp)
{
- boolean r = !sp.eos
- && !sp.dontMatch
- && ((sp.c >= '0' && sp.c <= '9')
- || (sp.c >= 'a' && sp.c <= 'f') || (sp.c >= 'A' && sp.c <= 'F'));
+ boolean r = !sp.eos && !sp.dontMatch
+ && ((sp.c >= '0' && sp.c <= '9') || (sp.c >= 'a' && sp.c <= 'f')
+ || (sp.c >= 'A' && sp.c <= 'F'));
return r;
}