// Find next wildcard in the pattern.
private boolean ruleMatches(String text, String pattern) {
        int patternPos = 0;
        int textPos = 0;
        int patternEnd = pattern.length();
        int textEnd = text.length();
        boolean containsEndChar = pattern.endsWith("$");
        if (containsEndChar) {
            patternEnd -= 1;
        }
        while ((patternPos < patternEnd) && (textPos < textEnd)) {
            // Find next wildcard in the pattern.
            int wildcardPos = pattern.indexOf('*', patternPos);
            if (wildcardPos == -1) {
                wildcardPos = patternEnd;
            }
            // If we're at a wildcard in the pattern, find the place in the text
            // where the character(s) after the wildcard match up with what's in
            // the text.
            if (wildcardPos == patternPos) {
                patternPos += 1;
                if (patternPos >= patternEnd) {
                    // Pattern ends with '*', we're all good.
                    return true;
                }
                // TODO - don't worry about having two '*' in a row?
                // Find the end of the pattern piece we need to match.
                int patternPieceEnd = pattern.indexOf('*', patternPos);
                if (patternPieceEnd == -1) {
                    patternPieceEnd = patternEnd;
                }
                boolean matched = false;
                int patternPieceLen = patternPieceEnd - patternPos;
                while ((textPos + patternPieceLen <= textEnd) && !matched) {
                    // See if patternPieceLen chars from text at textPos match
                    // chars from pattern at patternPos
                    matched = true;
                    for (int i = 0; i < patternPieceLen && matched; i++) {
                        if (text.charAt(textPos + i) != pattern.charAt(patternPos + i)) {
                            matched = false;
                        }
                    }
                    // If we matched, we're all set, otherwise we have to
                    // advance textPos
                    if (!matched) {
                        textPos += 1;
                    }
                }
                // If we matched, we're all set, otherwise we failed
                if (!matched) {
                    return false;
                }
            } else {
                // See if the pattern from patternPos to wildcardPos matches the
                // text starting at textPos
                while ((patternPos < wildcardPos) && (textPos < textEnd)) {
                    if (text.charAt(textPos++) != pattern.charAt(patternPos++)) {
                        return false;
                    }
                }
            }
        }
        // If we didn't reach the end of the pattern, make sure we're not at a
        // wildcard, that's a 0 or more match, so then we're still OK.
        while ((patternPos < patternEnd) && (pattern.charAt(patternPos) == '*')) {
            patternPos += 1;
        }
        // We're at the end, so we have a match if the pattern was completely
        // consumed, and either we consumed all the text or we didn't have to
        // match it all (no '$' at end of the pattern)
        return (patternPos == patternEnd) && ((textPos == textEnd) || !containsEndChar);
    }
}
while ((patternPos < patternEnd) && (textPos < textEnd)) {
// Find next wildcard in the pattern.
int wildcardPos = pattern.indexOf('*', patternPos);
if (wildcardPos == -1) {
private boolean ruleMatches(String text, String pattern) {
int patternPos = 0;
int textPos = 0;
int patternEnd = pattern.length();
int textEnd = text.length();
boolean containsEndChar = pattern.endsWith("$");
if (containsEndChar) {
patternEnd -= 1;
}
while ((patternPos < patternEnd) && (textPos < textEnd)) {
// Find next wildcard in the pattern.
int wildcardPos = pattern.indexOf('*', patternPos);
if (wildcardPos == -1) {
wildcardPos = patternEnd;
}
// If we're at a wildcard in the pattern, find the place in the text
// where the character(s) after the wildcard match up with what's in
// the text.
if (wildcardPos == patternPos) {
patternPos += 1;
if (patternPos >= patternEnd) {
private boolean ruleMatches(String text, String pattern) {
int patternPos = 0;
int textPos = 0;
int patternEnd = pattern.length();
int textEnd = text.length();
boolean containsEndChar = pattern.endsWith("$");
if (containsEndChar) {
patternEnd -= 1;
}
while ((patternPos < patternEnd) && (textPos < textEnd)) {
// Find next wildcard in the pattern.
int wildcardPos = pattern.indexOf('*', patternPos);
if (wildcardPos == -1) {
wildcardPos = patternEnd;
}
// If we're at a wildcard in the pattern, find the place in the text
// where the character(s) after the wildcard match up with what's in
// the text.
if (wildcardPos == patternPos) {
patternPos += 1;
if (patternPos >= patternEnd) {
// Pattern ends with '*', we're all good.
return true;
}
// TODO - don't worry about having two '*' in a row?
// Find the end of the pattern piece we need to match.
int patternPieceEnd = pattern.indexOf('*', patternPos);
if (patternPieceEnd == -1) {
patternPieceEnd = patternEnd;
}
boolean matched = false;