toString method

String toString ()
override

Returns a string representation of this object.

Implementation

String toString() {
  var buffer = new StringBuffer();

  if (min != null) {
    buffer.write(includeMin ? '>=' : '>');
    buffer.write(min);
  }

  if (max != null) {
    if (min != null) buffer.write(' ');
    if (includeMax) {
      buffer.write('<=');
      buffer.write(max);
    } else {
      buffer.write('<');
      if (max.isFirstPreRelease) {
        // Since `"<$max"` would parse the same as `"<$max-0"`, we just emit
        // `<$max` to avoid confusing "-0" suffixes.
        buffer.write("${max.major}.${max.minor}.${max.patch}");
      } else {
        buffer.write(max);

        // If `">=$min <$max"` would parse as `">=$min <$max-0"`, add `-*` to
        // indicate that actually does allow pre-release versions.
        var minIsPreReleaseOfMax = min != null &&
            min.isPreRelease &&
            equalsWithoutPreRelease(min, max);
        if (!max.isPreRelease && max.build.isEmpty && !minIsPreReleaseOfMax) {
          buffer.write("-∞");
        }
      }
    }
  }

  if (min == null && max == null) buffer.write('any');
  return buffer.toString();
}