关注开源代码的实际应用
- public static bool Wildcard(string pattern, string input)
- {
- return Wildcard(pattern, 0, input, 0, false);
- }
- public static bool Wildcard(string pattern, string input, bool insensitive)
- {
- return Wildcard(pattern, 0, input, 0, insensitive);
- }
- private static bool Wildcard(string pattern, int p, string input, int i, bool insensitive)
- {
- for(; ; )
- {
- char ic = input[i];
- char pc = pattern[p];
- switch(pc)
- {
- case '?':
- break;
- case '*':
- p++;
- for(int j = i; j < input.Length; j++)
- {
- if(Wildcard(pattern, p, input, j, insensitive))
- {
- return true;
- }
- }
- return false;
- default:
- if(insensitive)
- {
- ic = char.ToLower(ic);
- pc = char.ToLower(pc);
- }
- if(ic != pc)
- {
- return false;
- }
- break;
- }
- i++;
- p++;
- if(p >= pattern.Length)
- {
- if(i >= input.Length)
- {
- return true;
- }
- return false;
- }
- else if(i >= input.Length)
- {
- return false;
- }
- }
- }