System.Net.ShellExpression.IsMatch C# (CSharp) Method

IsMatch() private method

private IsMatch ( string target ) : bool
target string
return bool
        internal bool IsMatch(string target)
        {
            GlobalLog.Print("ShellServices.ShellExpression#" + ValidationHelper.HashString(this) + "::IsMatch() target:" + ValidationHelper.ToString(target));
            int i = 0;
            int j = 0;
            bool reverse = false;
            bool matched = false;

            while (true)
            {
                if (!reverse)
                {
                    if (j > target.Length)
                    {
                        break;
                    }

                    switch (pattern[i])
                    {
                        case ShExpTokens.Asterisk:
                            match[i++] = j = target.Length;
                            continue;

                        case ShExpTokens.Question:
                            if (j == target.Length)
                            {
                                reverse = true;
                            }
                            else
                            {
                                match[i++] = ++j;
                            }
                            continue;

                        case ShExpTokens.AugmentedDot:
                            if (j == target.Length)
                            {
                                match[i++] = j;
                            }
                            else if (target[j] == '.')
                            {
                                match[i++] = ++j;
                            }
                            else
                            {
                                reverse = true;
                            }
                            continue;

                        case ShExpTokens.AugmentedAsterisk:
                            if (j == target.Length || target[j] == '.')
                            {
                                reverse = true;
                            }
                            else
                            {
                                match[i++] = ++j;
                            }
                            continue;

                        case ShExpTokens.AugmentedQuestion:
                            if (j == target.Length || target[j] == '.')
                            {
                                match[i++] = j;
                            }
                            else
                            {
                                match[i++] = ++j;
                            }
                            continue;

                        case ShExpTokens.Start:
                            if (j != 0)
                            {
                                break;
                            }
                            match[i++] = 0;
                            continue;

                        case ShExpTokens.End:
                            if (j == target.Length)
                            {
                                matched = true;
                                break;
                            }
                            reverse = true;
                            continue;

                        default:
                            if (j < target.Length && (int) pattern[i] == (int) char.ToLowerInvariant(target[j]))
                            {
                                match[i++] = ++j;
                            }
                            else
                            {
                                reverse = true;
                            }
                            continue;
                    }
                }
                else
                {
                    switch (pattern[--i])
                    {
                        case ShExpTokens.Asterisk:
                        case ShExpTokens.AugmentedQuestion:
                            if (match[i] != match[i - 1])
                            {
                                j = --match[i++];
                                reverse = false;
                            }
                            continue;

                        case ShExpTokens.Start:
                        case ShExpTokens.End:
                            break;

                        case ShExpTokens.Question:
                        case ShExpTokens.AugmentedDot:
                        case ShExpTokens.AugmentedAsterisk:
                        default:
                            continue;
                    }
                }
                break;
            }

            GlobalLog.Print("ShellServices.ShellExpression#" + ValidationHelper.HashString(this) + "::IsMatch() return:" + matched.ToString());
            return matched;
        }

Usage Example

示例#1
0
        // See
        public bool shExpMatch(string host, string pattern)
        {
            GlobalLog.Print("WebProxyScriptHelper::shExpMatch() host:" + ValidationHelper.ToString(host) + " pattern:" + ValidationHelper.ToString(pattern));
            if (host == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_called_with_null_parameter, "WebProxyScriptHelper.shExpMatch()", "host"));
                }
                throw new ArgumentNullException("host");
            }
            if (pattern == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_called_with_null_parameter, "WebProxyScriptHelper.shExpMatch()", "pattern"));
                }
                throw new ArgumentNullException("pattern");
            }

            try
            {
                // This can throw - treat as no match.
                ShellExpression exp = new ShellExpression(pattern);
                return(exp.IsMatch(host));
            }
            catch (FormatException)
            {
                return(false);
            }
        }
All Usage Examples Of System.Net.ShellExpression::IsMatch