for (int i = 0; i < pattern.length; i++) {
char ch = pattern[i];
if (forceAbsolutePath && (lastToken == LAST_TOKEN_START) && (ch != SLASH)) {
throw new MalformedPatternException(getDefaultErrorMessage(pattern, i));
}
switch (ch) {
case SLASH:
// slash���治����slash, slash����λ�����ַ�(���ָ����force relative path�Ļ�)
if (lastToken == LAST_TOKEN_SLASH) {
throw new MalformedPatternException(getDefaultErrorMessage(pattern, i));
} else if (forceRelativePath && (lastToken == LAST_TOKEN_START)) {
throw new MalformedPatternException(getDefaultErrorMessage(pattern, i));
}
// ��Ϊ**�Ѿ�������slash, ���Բ���Ҫ�����ƥ��slash
if (lastToken != LAST_TOKEN_DOUBLE_STAR) {
buffer.append(REGEX_SLASH_NO_DUP);
}
lastToken = LAST_TOKEN_SLASH;
break;
case STAR:
int j = i + 1;
if ((j < pattern.length) && (pattern[j] == STAR)) {
i = j;
// **ǰ��ֻ����slash
if ((lastToken != LAST_TOKEN_START) && (lastToken != LAST_TOKEN_SLASH)) {
throw new MalformedPatternException(getDefaultErrorMessage(pattern, i));
}
lastToken = LAST_TOKEN_DOUBLE_STAR;
buffer.append(REGEX_FILE_PATH);
} else {
// *ǰ�治����*��**
if ((lastToken == LAST_TOKEN_STAR) || (lastToken == LAST_TOKEN_DOUBLE_STAR)) {
throw new MalformedPatternException(getDefaultErrorMessage(pattern, i));
}
lastToken = LAST_TOKEN_STAR;
buffer.append(REGEX_FILE_NAME);
}
break;
case QUESTION:
lastToken = LAST_TOKEN_QUESTION;
buffer.append(REGEX_FILE_NAME_SINGLE_CHAR);
break;
default:
// **��ֻ����slash
if (lastToken == LAST_TOKEN_DOUBLE_STAR) {
throw new MalformedPatternException(getDefaultErrorMessage(pattern, i));
}
if (Character.isLetterOrDigit(ch) || (ch == UNDERSCORE) || (ch == DASH)) {
// ����word�߽�, ��������ƥ��
if (lastToken == LAST_TOKEN_START) {
buffer.append(REGEX_WORD_BOUNDARY).append(ch); // ǰ�߽�
} else if ((i + 1) == pattern.length) {
buffer.append(ch).append(REGEX_WORD_BOUNDARY); // ��߽�
} else {
buffer.append(ch);
}
} else if (ch == DOT) {
buffer.append(ESCAPE_CHAR).append(DOT);
} else {
throw new MalformedPatternException(getDefaultErrorMessage(pattern, i));
}
lastToken = LAST_TOKEN_FILE_NAME;
}
}