Class SwiftPattern
- All Implemented Interfaces:
Serializable
This class internally uses a Pattern by transforming the SWIFT expression to a traditional
regular expression. As a result the SwiftPattern API is similar to the Pattern API.
The SwiftPattern class partially supports the SWIFT expression by using the following constructions :
| n | digits (numeric characters 0 to 9 only) |
| a | uppercase letters (alphabetic characters A-Z only) |
| c | uppercase and lowercase case alphanumeric characters (A-Z, a-z and 0-9) |
| e | blank space |
| nn! | fixed length |
| nn | maximum length |
Here are some examples of SWIFT expressions that are supported by this SwiftPattern :
4!n(corresponding regex[0-9]{4}) : four digits4!c3a(corresponding regex[A-Za-z0-9]{4}[A-Z]{1,3}) : four upper or lowercase alphanumeric characters followed by one to three uppercase letters2e4!a(corresponding regex[ ]{1,2}[A-Z]{4}) : one or two spaces followed by four uppercase letters
This class has some limitations in order to prevent stack overflows, as explained in
Regular
expressions should not overflow the stack. The maximum supported length is set to 999 and the maximum number of
groups (such as 4!n) is 1000. these limitations are far above anything that can be seen in SWIFT documents
and should be sufficient.
Instances of this class are immutable and thread-safe.
This class implements Serializable for convenience, but you are encouraged to use the normalized string representation if possible. Note that no validity check is done during deserialization.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic SwiftPatternCompiles the given SWIFT expression into a SwiftPattern.booleanReturns thejava Patternbuild using the SWIFT expression.Returns the SWIFT expression from which this pattern was compiled.inthashCode()matcher(CharSequence input) Creates a matcher that will match the given input against this pattern.toString()Returns this SWIFT pattern expression as a String.
-
Method Details
-
compile
Compiles the given SWIFT expression into a SwiftPattern.- Parameters:
expression- The expression to be compiled- Returns:
- a SwiftPattern representing the given expression
- Throws:
SwiftPatternSyntaxException- if the expression's syntax is invalid
-
matcher
Creates a matcher that will match the given input against this pattern.- Parameters:
input- The character sequence to be matched- Returns:
- a new matcher for this pattern
-
getExpression
Returns the SWIFT expression from which this pattern was compiled.- Returns:
- a non-null string
-
getEquivalentJavaPattern
Returns thejava Patternbuild using the SWIFT expression.- Returns:
- a non-null pattern
-
equals
-
hashCode
public int hashCode() -
toString
Returns this SWIFT pattern expression as a String.
-