boolean containsStar = false; for (char c : patArr) { if (c == '*') {
containsStar = true; break;
}
}
if (!containsStar) { // No '*'s, so we make a shortcut if (patIdxEnd != strIdxEnd) { returnfalse; // Pattern and string do not have the same size
} for (int i = 0; i <= patIdxEnd; i++) {
ch = patArr[i]; if (ch != '?') { if (different(caseSensitive, ch, strArr[i])) { returnfalse; // Character mismatch
}
}
} returntrue; // String matches against pattern
}
if (patIdxEnd == 0) { returntrue; // Pattern contains only '*', which matches anything
}
// Process characters before first star while (true) {
ch = patArr[patIdxStart]; if (ch == '*' || strIdxStart > strIdxEnd) { break;
} if (ch != '?') { if (different(caseSensitive, ch, strArr[strIdxStart])) { returnfalse; // Character mismatch
}
}
patIdxStart++;
strIdxStart++;
} if (strIdxStart > strIdxEnd) { // All characters in the string are used. Check if only '*'s are // left in the pattern. If so, we succeeded. Otherwise failure. return allStars(patArr, patIdxStart, patIdxEnd);
}
// Process characters after last star while (true) {
ch = patArr[patIdxEnd]; if (ch == '*' || strIdxStart > strIdxEnd) { break;
} if (ch != '?') { if (different(caseSensitive, ch, strArr[strIdxEnd])) { returnfalse; // Character mismatch
}
}
patIdxEnd--;
strIdxEnd--;
} if (strIdxStart > strIdxEnd) { // All characters in the string are used. Check if only '*'s are // left in the pattern. If so, we succeeded. Otherwise failure. return allStars(patArr, patIdxStart, patIdxEnd);
}
// process pattern between stars. padIdxStart and patIdxEnd point // always to a '*'. while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patArr[i] == '*') {
patIdxTmp = i; break;
}
} if (patIdxTmp == patIdxStart + 1) { // Two stars next to each other, skip the first one.
patIdxStart++; continue;
} // Find the pattern between padIdxStart & padIdxTmp in str between // strIdxStart & strIdxEnd int patLength = (patIdxTmp - patIdxStart - 1); int strLength = (strIdxEnd - strIdxStart + 1); int foundIdx = -1;
strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) {
ch = patArr[patIdxStart + j + 1]; if (ch != '?') { if (different(caseSensitive, ch,
strArr[strIdxStart + i + j])) { continue strLoop;
}
}
}
// All characters in the string are used. Check if only '*'s are left // in the pattern. If so, we succeeded. Otherwise failure. return allStars(patArr, patIdxStart, patIdxEnd);
}
privatestaticboolean allStars(char[] chars, int start, int end) { for (int i = start; i <= end; ++i) { if (chars[i] != '*') { returnfalse;
}
} returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.