/**
* Simple RegEx compare, where the single supported RE chars are "." - single
* and "*" for multiple occurences.
* @param inpStr - Input string to be compared.
* @param reStr - Input RE.
* @return
*/
{
boolean retVal = true;
int i, j; // Indexes in the input RegEx & String
char inpChar; // Current char from the input string/
char reChar; // Current RE's char.
char reCntChar; // contsind '1' - one occurence or "*" for multiple.
char reNextChar = '\0'; // For "*" - the next character, which follows the "*".
int inpStrLen = (inpStr == null) ? -1 : inpStr.length();
int reLen = (reStr == null) ? -1 : reStr.length();
if (reLen <= 0 || inpStrLen <= 0)
return(false);
i = j = 0;
// Scan the RE:
while (retVal && i < reLen)
{
// Determine what is the next RE char:
reChar = reStr.charAt(i++);
if (reChar == '*')
throw new PatternSyntaxException("* without preceeding char", reStr, i);
reCntChar = (i < reLen) ? reStr.charAt(i) : '1';
// For '*' - get the blocking char:
if (reCntChar == '*')
{
i++; // Advance past '*'
reNextChar = (i < reLen) ? reStr.charAt(i) : '\0';
}
// Compare it to the current RE char:
boolean getNextReChar = false;
while (retVal && j < inpStrLen && !getNextReChar)
{
// Get the next char from the input string:
inpChar = inpStr.charAt(j++);
// If the current RE char is not '.' and it does not match
// the current input character - nothing to do:
if (reChar != '.' && inpChar != reChar)
{
retVal = false;
break;
}
// Current input char matches:
// If the Count RE char is not - '*' advance to the next RE.
// Else if the next input character matches the first Char,
// which is next to '*':
if (reCntChar != '*')
getNextReChar = true;
else
{
// Check if the next input character matches the next
// RE char, so leave the scan on the input string:
if (reNextChar != '\0' && j < inpStrLen
&& inpStr.charAt(j) == reNextChar)
getNextReChar = true;
}
}
}
// Have we reached the end of the RE before the end
// of the input string?
if (retVal && i >= reLen && j < inpStrLen)
retVal = false;
return(retVal);
}