Exemple #1
0
 public static bool MatchesSimpleExpression(string str, string pattern, Net.Vpc.Upa.Impl.Util.PatternType type)
 {
     return(new Net.Vpc.Upa.Impl.Util.Regexp.PortablePattern(SimpexpToRegexp(pattern, type)).Matcher(str == null ? "" : str).Matches());
 }
Exemple #2
0
        /**
         * *
         * **
         *
         * @param pattern
         * @return
         */
        public static string SimpexpToRegexp(string pattern, Net.Vpc.Upa.Impl.Util.PatternType type)
        {
            if (pattern == null)
            {
                pattern = "*";
            }
            int i = 0;

            char[] cc = pattern.ToCharArray();
            System.Text.StringBuilder sb = new System.Text.StringBuilder("^");
            while (i < cc.Length)
            {
                char c = cc[i];
                switch (c)
                {
                case '.':
                case '!':
                case '$':
                case '[':
                case ']':
                case '(':
                case ')':
                case '?':
                case '^':
                case '\\':
                {
                    sb.Append('\\').Append(c);
                    break;
                }

                case '*':
                {
                    switch (type)
                    {
                    case Net.Vpc.Upa.Impl.Util.PatternType.DOT_PATH:
                    {
                        if (i + 1 < cc.Length && cc[i + 1] == '*')
                        {
                            i++;
                            sb.Append("[a-zA-Z_0-9$.]*");
                        }
                        else
                        {
                            sb.Append("[a-zA-Z_0-9$]*");
                        }
                        break;
                    }

                    case Net.Vpc.Upa.Impl.Util.PatternType.SLASH_PATH:
                    {
                        if (i + 1 < cc.Length && cc[i + 1] == '*')
                        {
                            i++;
                            sb.Append("[a-zA-Z_0-9$/]*");
                        }
                        else
                        {
                            sb.Append("[a-zA-Z_0-9$]*");
                        }
                        break;
                    }

                    case Net.Vpc.Upa.Impl.Util.PatternType.ANY:
                    {
                        sb.Append(".*");
                        break;
                    }

                    default:
                    {
                        throw new System.ArgumentException("Unsupported");
                    }
                    }
                    break;
                }

                default:
                {
                    sb.Append(c);
                }
                break;
                }
                i++;
            }
            sb.Append('$');
            return(sb.ToString());
        }