matches static method

bool matches(
  1. Topic pattern,
  2. Topic topic
)

Whether pattern matches the concrete topic.

Implementation

static bool matches(Topic pattern, Topic topic) {
  if (pattern.type != topic.type) return false;
  if (isPattern(topic)) return false;

  final patternPaths = pattern.paths;
  final topicPaths = topic.paths;
  var index = 0;
  for (; index < patternPaths.length; index++) {
    final token = patternPaths[index];
    if (token == tail) {
      return index == patternPaths.length - 1 && index < topicPaths.length;
    }
    if (index >= topicPaths.length) return false;
    if (token == single) continue;
    if (token != topicPaths[index]) return false;
  }
  return index == topicPaths.length;
}