matches method

bool matches(
  1. VersionRange b
)

Returns true if two VersionRanges overlap.

Overlap rules:

  • If both have start and end: intervals intersect
  • Open-ended ranges are treated as unbounded on that side
  • Exact-match ranges (=1.2.3 → [1.2.3, 1.2.4)) work naturally

Examples: >=1.0.0 <2.0.0 intersects ^1.5.0 → true >=2.0.0 <3.0.0 intersects <1.0.0 → false ^3.0.0 intersects 3.5.0 → true

Implementation

bool matches(VersionRange b) {
  final a = this;

  // Treat null start as "unbounded below"
  final aStart = a.start;
  final bStart = b.start;

  // Treat null end as "unbounded above"
  final aEnd = a.end;
  final bEnd = b.end;

  // Two ranges overlap if:
  //
  //   (a.start < b.end) AND (b.start < a.end)
  //
  // Null-end means infinite.
  final aStartsBeforeBEnds = bEnd == null || aStart == null || aStart < bEnd;
  final bStartsBeforeAEnds = aEnd == null || bStart == null || bStart < aEnd;

  return aStartsBeforeBEnds && bStartsBeforeAEnds;
}