Esempio n. 1
0
        private static IEnumerable<BaseOperator> ParsePatternWorker(string patternText)
        {
            var pattern = new PatternWrapper(patternText);

              if (pattern.IsEmpty)
            yield return new OpNoMatch();

              // Check for "/" suffix
              if (IsPathSeparator(pattern.Last)) {
            yield return new OpDirectoryOnly();
            pattern.RemoveLast();
              }

              if (pattern.IsEmpty)
            yield return new OpNoMatch();

              // Check for "/" prefix
              if (IsPathSeparator(pattern.First))
            pattern.Skip(1);
              else
            yield return new OpRelativeDirectory();

              // Check for "**/" prefix
              if (pattern.StartsWith("**\\"))
            pattern.Skip(3);

              if (pattern.IsEmpty)
            yield return new OpNoMatch();

              while (!pattern.IsEmpty) {
            var anyDirIndex = pattern.IndexOf("\\**\\");
            if (anyDirIndex >= 0) {
              if (anyDirIndex >= pattern.Index)
            yield return new OpText(pattern.Take(anyDirIndex - pattern.Index));
              yield return new OpRecursiveDir();
              pattern.Skip(4);
              continue;
            }

            var asteriskIndex = pattern.IndexOf("*");
            if (asteriskIndex >= 0) {
              if (asteriskIndex > pattern.Index)
            yield return new OpText(pattern.Take(asteriskIndex - pattern.Index));
              yield return new OpAsterisk();
              pattern.Skip(1);
            } else {
              yield return new OpText(pattern.Take(pattern.Remaining));
            }
              }
        }
Esempio n. 2
0
        private static IEnumerable <BaseOperator> ParsePatternWorker(PatternWrapper pattern)
        {
            var result = new List <BaseOperator>();

            if (pattern.IsEmpty)
            {
                result.Add(new OpIsNoMatch());
                return(result);
            }

            // Check for "/" suffix
            if (pattern.Last == PathSeparator)
            {
                result.Add(new OpIsDirectoryOnly());
                pattern.RemoveLast();
            }

            if (pattern.IsEmpty)
            {
                result.Add(new OpIsNoMatch());
                return(result);
            }

            // Check for "/" prefix
            if (pattern.First == PathSeparator)
            {
                pattern.Skip(1);
            }
            else
            {
                result.Add(new OpIsRelativeDirectory());
            }

            // Check for "**/" prefix
            if (pattern.StartsWith(AnyDirMatchPrefix))
            {
                pattern.Skip(3);
            }

            if (pattern.IsEmpty)
            {
                result.Add(new OpIsNoMatch());
                return(result);
            }

            var    sb        = new StringBuilder();
            Action addOpText = () => {
                if (sb.Length > 0)
                {
                    result.Add(new OpText(sb.ToString()));
                    sb.Clear();
                }
            };

            while (!pattern.IsEmpty)
            {
                if (pattern.StartsWith(AnyDirMatch))
                {
                    addOpText();
                    result.Add(new OpRecursiveDir());
                    pattern.Skip(4);
                }
                else if (pattern.First == PathSeparator)
                {
                    addOpText();
                    result.Add(new OpDirectorySeparator());
                    pattern.Skip(1);
                }
                else if (pattern.First == '*')
                {
                    addOpText();
                    result.Add(new OpAsterisk());
                    pattern.Skip(1);
                }
                else
                {
                    sb.Append(pattern.First);
                    pattern.Skip(1);
                }
            }
            addOpText();
            return(result);
        }
Esempio n. 3
0
    private static IEnumerable<BaseOperator> ParsePatternWorker(PatternWrapper pattern) {
      var result = new List<BaseOperator>();

      if (pattern.IsEmpty) {
        result.Add(new OpIsNoMatch());
        return result;
      }

      // Check for "/" suffix
      if (pattern.Last == PathSeparator) {
        result.Add(new OpIsDirectoryOnly());
        pattern.RemoveLast();
      }

      if (pattern.IsEmpty) {
        result.Add(new OpIsNoMatch());
        return result;
      }

      // Check for "/" prefix
      if (pattern.First == PathSeparator)
        pattern.Skip(1);
      else
        result.Add(new OpIsRelativeDirectory());

      // Check for "**/" prefix
      if (pattern.StartsWith(AnyDirMatchPrefix))
        pattern.Skip(3);

      if (pattern.IsEmpty) {
        result.Add(new OpIsNoMatch());
        return result;
      }

      var sb = new StringBuilder();
      Action addOpText = () => {
        if (sb.Length > 0) {
          result.Add(new OpText(sb.ToString()));
          sb.Clear();
        }
      };
      while (!pattern.IsEmpty) {
        if (pattern.StartsWith(AnyDirMatch)) {
          addOpText();
          result.Add(new OpRecursiveDir());
          pattern.Skip(4);
        } else if (pattern.First == PathSeparator) {
          addOpText();
          result.Add(new OpDirectorySeparator());
          pattern.Skip(1);
        } else if (pattern.First == '*') {
          addOpText();
          result.Add(new OpAsterisk());
          pattern.Skip(1);
        } else {
          sb.Append(pattern.First);
          pattern.Skip(1);
        }
      }
      addOpText();
      return result;
    }