patternMatches method

bool patternMatches({
  1. required String testPattern,
  2. required String inputPattern,
})

Checks if testPattern matches an inputPattern testPattern may for example be a pattern

Implementation

bool patternMatches({
  required String testPattern,
  required String inputPattern,
}) {
  // Simple match check for rule patterns like "*", "?", "**", etc.
  switch (this) {
    case IgnorePatternRules.suffix:
      String parsedPattern = testPattern.replaceFirst(pattern, "");
      return inputPattern.endsWith(parsedPattern) && inputPattern.replaceFirst(parsedPattern, "").isNotEmpty;

    case IgnorePatternRules.single:
      if (testPattern.length != inputPattern.length) return false;

      String parsedPattern = testPattern.replaceAll(pattern, "");
      String parsedInput = "";

      //Replace with empty string and match the strings
      for (int i = 0; i < testPattern.length; i++) {
        String testPatternChar = testPattern[i];

        //skip character
        if (testPatternChar == pattern) continue;
        parsedInput += testPatternChar;
      }

      return parsedPattern == parsedInput;

    case IgnorePatternRules.contains:
      String parsedPattern = testPattern.replaceAll(pattern, "");
      return inputPattern.contains(parsedPattern);

    case IgnorePatternRules.pathFromRoot:
      return inputPattern.startsWith(testPattern);
    case IgnorePatternRules.exactMatch:
      return testPattern == inputPattern;
  }
}