void Url::AppendPath(string_view piece, bool encode) {
  if (piece.empty() || piece == "/") {
    return;
  }

  if (path_.empty() || path_ == "/") {
    path_.clear();
    if (piece.front() != '/') {
      path_.push_back('/');
    }
  } else if (path_.back() == '/' && piece.front() == '/') {
    path_.pop_back();
  } else if (path_.back() != '/' && piece.front() != '/') {
    path_.push_back('/');
  }

  if (encode) {
    path_.append(Url::EncodePath(piece));
  } else {
    path_.append(ToString(piece));
  }
}
void Url::AppendPath(string_view piece, bool encode) {
  if (piece.empty() || piece == "/") {
    return;
  }

  if (path_.empty() || path_ == "/") {
    path_.clear();
    if (piece.front() != '/') {
      path_.push_back('/');
    }
  } else if (path_.back() == '/' && piece.front() == '/') {
    path_.pop_back();
  } else if (path_.back() != '/' && piece.front() != '/') {
    path_.push_back('/');
  }

  if (encode) {
    path_.append(Url::EncodePath(piece));
  } else {
    path_.append(ToString(piece));
  }
}