int compare()

in fatal/string/rope.h [1337:1362]


  int compare(string_view rhs) const {
    for (piece_index i = 0, pieces = pieces_.size(); i < pieces; ++i) {
      if (!rhs) {
        return 1;
      }

      auto piece = pieces_[i].ref();
      assert(piece);

      auto const length = std::min(rhs.size(), piece.size());
      assert(length > 0);

      if (auto const result = std::strncmp(piece.data(), rhs.data(), length)) {
        return result;
      }

      if (length == rhs.size()) {
        return length != piece.size();
      }

      assert(length == piece.size());
      rhs += length;
    }

    return -!rhs.empty();
  }