예제 #1
0
            internal new static WildcardSharpElement Create(string pattern, ref int patternIndex)
            {
                patternIndex++;

                var element = new WildcardSharpElement();

                element.Next = WildcardElement.Create(pattern, ref patternIndex);

                return(element);
            }
예제 #2
0
        private WildcardElement Build()
        {
            string pattern = _pattern;

            if (_caseInsensitive)
            {
                pattern = pattern.ToLower();
            }

            int patternIndex = 0;

            return(WildcardElement.Create(pattern, ref patternIndex));
        }
예제 #3
0
            internal new static WildcardStringElement Create(string pattern, ref int patternIndex)
            {
                int patternLength = pattern.Length;
                var builder       = new StringBuilder(patternLength - patternLength);

                while (patternIndex < patternLength)
                {
                    switch (pattern[patternIndex])
                    {
                    case '\\':
                    {
                        patternIndex++;

                        if (patternIndex < patternLength)
                        {
                            builder.Append(pattern[patternIndex++]);
                        }
                    }
                        continue;

                    case '*':
                    case '?':
                    case '#':
                    case '[':
                        break;

                    default:
                    {
                        builder.Append(pattern[patternIndex++]);
                    }
                        continue;
                    }

                    break;
                }

                var element = new WildcardStringElement();

                element.Pattern = builder.ToString();
                element.Next    = WildcardElement.Create(pattern, ref patternIndex);

                return(element);
            }
예제 #4
0
            internal new static WildcardRangeElement Create(string pattern, ref int patternIndex)
            {
                patternIndex++;
                int patternLength = pattern.Length;

                bool negate = false;
                var  chars  = new HashSet <char>();

                if (patternIndex < patternLength && pattern[patternIndex] == '!')
                {
                    patternIndex++;
                    negate = true;
                }

                bool closed = false;

                while (patternIndex < patternLength)
                {
                    char ch = pattern[patternIndex];
                    switch (ch)
                    {
                    case ']':
                    {
                        patternIndex++;
                        closed = true;
                    }
                    break;

                    case '\\':
                    {
                        patternIndex++;

                        if (patternIndex < patternLength)
                        {
                            ch = pattern[patternIndex++];
                            if (!chars.Contains(ch))
                            {
                                chars.Add(ch);
                            }
                        }
                    }
                        continue;

                    default:
                    {
                        if (char.IsLetter(ch))
                        {
                            patternIndex++;

                            if (patternIndex + 1 < patternLength &&
                                pattern[patternIndex] == '-' &&
                                char.IsLetter(pattern[patternIndex + 1]))
                            {
                                patternIndex++;                                                 // -
                                char fromChar = ch;
                                char toChar   = pattern[patternIndex++];
                                for (char c = fromChar; c <= toChar; c++)
                                {
                                    if (!chars.Contains(c))
                                    {
                                        chars.Add(c);
                                    }
                                }
                            }
                            else
                            {
                                if (!chars.Contains(ch))
                                {
                                    chars.Add(ch);
                                }
                            }
                        }
                        else if (char.IsDigit(ch))
                        {
                            patternIndex++;

                            if (patternIndex + 1 < patternLength &&
                                pattern[patternIndex] == '-' &&
                                char.IsDigit(pattern[patternIndex + 1]))
                            {
                                patternIndex++;                                                 // -
                                char fromChar = ch;
                                char toChar   = pattern[patternIndex++];
                                for (char c = fromChar; c <= toChar; c++)
                                {
                                    if (!chars.Contains(c))
                                    {
                                        chars.Add(c);
                                    }
                                }
                            }
                            else
                            {
                                if (!chars.Contains(ch))
                                {
                                    chars.Add(ch);
                                }
                            }
                        }
                        else
                        {
                            patternIndex++;

                            if (!chars.Contains(ch))
                            {
                                chars.Add(ch);
                            }
                        }
                    }
                        continue;
                    }

                    break;
                }

                if (!closed || chars.Count == 0)
                {
                    return(null);
                }

                var element = new WildcardRangeElement();

                element.Negate = negate;
                element.Chars  = chars;
                element.Next   = WildcardElement.Create(pattern, ref patternIndex);

                return(element);
            }