Repository: google/googletest
File: googletest/src/gtest.cc (C++)

Code before:
            ++name;
            continue;
          }
          break;
        case '*':
          // Match zero or more characters. Start by skipping over the wildcard
          // and matching zero characters from name. If that fails, restart and
          // match one more character than the last attempt.
          pattern_next = pattern;
          name_next = name + 1;
          ++pattern;
          continue;
      }
    }
    // Failed to match a character. Restart if possible.
    if (name_begin < name_next && name_next <= name_end) {
      pattern = pattern_next;
      name = name_next;
      continue;
    }
    return false;
  }
  return true;
}

static bool IsGlobPattern(const std::string& pattern) {
  return std::any_of(pattern.begin(), pattern.end(),
                     [](const char c) { return c == '?' || c == '*'; });
}

namespace {

class UnitTestFilter {
 public:
  UnitTestFilter() = default;

  // Constructs a filter from a string of patterns separated by `:`.
  explicit UnitTestFilter(const std::string& filter) {
    // By design "" filter matches "" string.
    SplitString(filter, ':', &glob_patterns_);
    const auto exact_match_pattern_begin = std::partition(
        glob_patterns_.begin(), glob_patterns_.end(), &IsGlobPattern);
    exact_match_patterns_.insert(exact_match_pattern_begin,
                                 glob_patterns_.end());
    glob_patterns_.erase(exact_match_pattern_begin, glob_patterns_.end());
  }

  // Returns true if and only if name matches at least one of the patterns in
  // the filter.
  bool MatchesName(const std::string& name) const {
    return exact_match_patterns_.count(name) ||

Review comment (refactor):
Can we move this function into the unnamed namespace below and drop the `static`?

This isn't a class method, and the unnamed namespace will guarantee internal linkage.

Code after:
            ++name;
            continue;
          }
          break;
        case '*':
          // Match zero or more characters. Start by skipping over the wildcard
          // and matching zero characters from name. If that fails, restart and
          // match one more character than the last attempt.
          pattern_next = pattern;
          name_next = name + 1;
          ++pattern;
          continue;
      }
    }
    // Failed to match a character. Restart if possible.
    if (name_begin < name_next && name_next <= name_end) {
      pattern = pattern_next;
      name = name_next;
      continue;
    }
    return false;
  }
  return true;
}

namespace {

bool IsGlobPattern(const std::string& pattern) {
  return std::any_of(pattern.begin(), pattern.end(),
                     [](const char c) { return c == '?' || c == '*'; });
}

class UnitTestFilter {
 public:
  UnitTestFilter() = default;

  // Constructs a filter from a string of patterns separated by `:`.
  explicit UnitTestFilter(const std::string& filter) {
    // By design "" filter matches "" string.
    std::vector<std::string> all_patterns;
    SplitString(filter, ':', &all_patterns);
    const auto exact_match_patterns_begin = std::partition(
        all_patterns.begin(), all_patterns.end(), &IsGlobPattern);

    glob_patterns_.reserve(exact_match_patterns_begin - all_patterns.begin());
    std::move(all_patterns.begin(), exact_match_patterns_begin, std::inserter(glob_patterns_, glob_patterns_.begin()));
    std::move(exact_match_patterns_begin, all_patterns.end(), std::inserter(exact_match_patterns_, exact_match_patterns_.begin()));
  }

  // Returns true if and only if name matches at least one of the patterns in
  // the filter.