com.borland.primetime.util
Class RegularExpression

java.lang.Object
  |
  +--com.borland.primetime.util.RegularExpression

public class RegularExpression
extends java.lang.Object

Currently implements a simple regular expression matching engine that interprets only "*", "?" and "\" as special characters. An asterisk matches any sequence of characters, including none. A question mark matches any single character, and a backslash indicates that the character that follows should be interpreted as a literal character, allowing any of the three special characters to be matched directly.


Inner Class Summary
static class RegularExpression.MatchResult
           
 
Field Summary
static char CHAR_ANY
          The '?' expression.
static char CHAR_ESCAPE
          The '\\' expression.
static char CHAR_WILDCARD
          The '*' expression.
static RegularExpression.MatchResult NO_MATCH
          The non-match result which has both the start index and length as -1.
 
Constructor Summary
RegularExpression(java.lang.String pattern)
          Creates a new case-sensitive RegularExpression instance for the specified pattern.
RegularExpression(java.lang.String pattern, boolean caseSensitive)
          Creates a new RegularExpression instance for the specified pattern and case sensitivity.
 
Method Summary
 boolean exactMatch(char[] test)
          Tests the specified array of characters to see if the pattern matches the entire sequence.
 boolean exactMatch(char[] test, int startIndex, int endIndex)
          Tests a subset of the specified array of characters to see if the pattern matches the entire subset.
 boolean exactMatch(java.lang.String test)
          Tests the specified string to see if the pattern matches the entire string.
 RegularExpression.MatchResult findSubstringMatch(char[] test, int startIndex, int endIndex)
          Tests a subset of the the specified array of characters to see if the pattern matches any portion of the subset.
 RegularExpression.MatchResult findSubstringMatch(java.lang.String test)
          Tests the specified string to see if the pattern matches any portion of the string.
 boolean isBreakOnNewline()
          Describes whether or not the pattern will match wildcards to sequences of characters that contain a newline.
 boolean isCaseSensitive()
          Describes whether or not the pattern is case-sensitive.
 boolean isPatternMatch()
          Describes whether or not wildcard characters and escape sequences are evaluated specially.
static boolean isSpecialChar(char character)
          Describes whether a given character will be treated as a literal or is treated specially and needs to be escaped to be used as a literal.
 boolean prefixMatch(char[] test)
          Tests the specified array of characters to see if the pattern matches some portion of the sequence starting with the first character.
 boolean prefixMatch(char[] test, int startIndex, int endIndex)
          Tests a subset of the specified array of characters to see if the pattern matches some portion of the subset starting with the first character of the subset.
 boolean prefixMatch(java.lang.String test)
          Tests the specified string to see if the pattern matches some portion of the string starting with the first character.
 void setBreakOnNewline(boolean breakOnNewline)
          Changes whether or not the pattern will match wildcards to sequences of characters that contain a newline.
 void setPatternMatch(boolean patternMatch)
          Changes whether or not wildcard characters and escape sequences are evaluated specially.
 int substringMatch(char[] test)
          Tests the specified array of characters to see if the pattern matches any portion of the sequence.
 int substringMatch(char[] test, int startIndex, int endIndex)
          Tests a subset of the specified array of characters to see if the pattern matches any portion of the subset.
 int substringMatch(java.lang.String test)
          Tests the specified string to see if the pattern matches any portion of the string.
 java.lang.String toString()
          Returns a description useful for diagnostic purposes but not much else.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHAR_ANY

public static final char CHAR_ANY
The '?' expression.

CHAR_WILDCARD

public static final char CHAR_WILDCARD
The '*' expression.

CHAR_ESCAPE

public static final char CHAR_ESCAPE
The '\\' expression.

NO_MATCH

public static final RegularExpression.MatchResult NO_MATCH
The non-match result which has both the start index and length as -1.
Constructor Detail

RegularExpression

public RegularExpression(java.lang.String pattern)
Creates a new case-sensitive RegularExpression instance for the specified pattern.
Parameters:
pattern - A non-null string of literal and wildcard characters.

RegularExpression

public RegularExpression(java.lang.String pattern,
                         boolean caseSensitive)
Creates a new RegularExpression instance for the specified pattern and case sensitivity.
Parameters:
pattern - A non-null string of literal and wildcard characters.
caseSensitive - True if the pattern should be case sensitive, false otherwise.
Method Detail

isSpecialChar

public static boolean isSpecialChar(char character)
Describes whether a given character will be treated as a literal or is treated specially and needs to be escaped to be used as a literal.
Parameters:
character - The character to be tested.
Returns:
True if the character needs to be escaped, false otherwise.

isCaseSensitive

public boolean isCaseSensitive()
Describes whether or not the pattern is case-sensitive.
Returns:
True if the pattern is case sensitive, false otherwise.

setBreakOnNewline

public void setBreakOnNewline(boolean breakOnNewline)
Changes whether or not the pattern will match wildcards to sequences of characters that contain a newline.
Parameters:
breakOnNewline - True if newline is a valid character in a wildcard match, false otherwise.

isBreakOnNewline

public boolean isBreakOnNewline()
Describes whether or not the pattern will match wildcards to sequences of characters that contain a newline.
Returns:
True if newline is a valid character in a wildcard match, false otherwise.

setPatternMatch

public void setPatternMatch(boolean patternMatch)
Changes whether or not wildcard characters and escape sequences are evaluated specially.
Parameters:
patternMatch - True if the wildcard characters and escape sequences should be evaluated specially, false if all characters in the pattern should be treated as literals.

isPatternMatch

public boolean isPatternMatch()
Describes whether or not wildcard characters and escape sequences are evaluated specially.
Returns:
True if the wildcard characters and escape sequences are evaluated specially, false if all characters in the pattern are to be treated as literals.

prefixMatch

public boolean prefixMatch(java.lang.String test)
Tests the specified string to see if the pattern matches some portion of the string starting with the first character.
Parameters:
test - The string to be tested.
Returns:
True if a match is found, false otherwise.

exactMatch

public boolean exactMatch(java.lang.String test)
Tests the specified string to see if the pattern matches the entire string.
Parameters:
test - The string to be tested.
Returns:
True if a match is found, false otherwise.

substringMatch

public int substringMatch(java.lang.String test)
Tests the specified string to see if the pattern matches any portion of the string.
Parameters:
test - The string to be tested.
Returns:
The offset at which the match was located, or -1 if no match was found.

findSubstringMatch

public RegularExpression.MatchResult findSubstringMatch(java.lang.String test)
Tests the specified string to see if the pattern matches any portion of the string.
Returns:
An object describing the range of characters that were matched, or RegularExpression.NO_MATCH if no match is found.

prefixMatch

public boolean prefixMatch(char[] test)
Tests the specified array of characters to see if the pattern matches some portion of the sequence starting with the first character.
Parameters:
test - The array of characters to be tested.
Returns:
True if a match is found, false otherwise.

exactMatch

public boolean exactMatch(char[] test)
Tests the specified array of characters to see if the pattern matches the entire sequence.
Parameters:
test - The array of characters to be tested.
Returns:
True if a match is found, false otherwise.

substringMatch

public int substringMatch(char[] test)
Tests the specified array of characters to see if the pattern matches any portion of the sequence.
Parameters:
test - The array of characters to be tested.
Returns:
The offset at which the match was located, or -1 if no match was found.

prefixMatch

public boolean prefixMatch(char[] test,
                           int startIndex,
                           int endIndex)
Tests a subset of the specified array of characters to see if the pattern matches some portion of the subset starting with the first character of the subset.
Parameters:
test - The array of characters to be tested.
startIndex - The offset of the first character in the subset to be tested.
startIndex - One greater than the offset of the last character in the subset to be tested.
Returns:
True if a match is found, false otherwise.

exactMatch

public boolean exactMatch(char[] test,
                          int startIndex,
                          int endIndex)
Tests a subset of the specified array of characters to see if the pattern matches the entire subset.
Parameters:
test - The array of characters to be tested.
startIndex - The offset of the first character in the subset to be tested.
startIndex - One greater than the offset of the last character in the subset to be tested.
Returns:
True if a match is found, false otherwise.

substringMatch

public int substringMatch(char[] test,
                          int startIndex,
                          int endIndex)
Tests a subset of the specified array of characters to see if the pattern matches any portion of the subset.
Parameters:
test - The array of characters to be tested.
startIndex - The offset of the first character in the subset to be tested.
startIndex - One greater than the offset of the last character in the subset to be tested.
Returns:
The offset at which the match was located, or -1 if no match was found.

findSubstringMatch

public RegularExpression.MatchResult findSubstringMatch(char[] test,
                                                        int startIndex,
                                                        int endIndex)
Tests a subset of the the specified array of characters to see if the pattern matches any portion of the subset.
Parameters:
test - The array of characters to be tested.
startIndex - The offset of the first character in the subset to be tested.
startIndex - One greater than the offset of the last character in the subset to be tested.
Returns:
An object describing the range of characters that were matched, or RegularExpression.NO_MATCH if no match is found.

toString

public java.lang.String toString()
Returns a description useful for diagnostic purposes but not much else.
Overrides:
toString in class java.lang.Object
Returns:
A non-null String containing the pattern used internally for matching purposes.