summaryrefslogtreecommitdiffstats
path: root/net/base/host_port_pair.cc
blob: 645d95839d35c7ec043006094a1a3fc38e49805d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/base/host_port_pair.h"
#include "base/string_util.h"

namespace net {

HostPortPair::HostPortPair() : port_(0) {}
HostPortPair::HostPortPair(const std::string& in_host, uint16 in_port)
    : host_(in_host), port_(in_port) {}

std::string HostPortPair::ToString() const {
  // Check to see if the host is an IPv6 address.  If so, added brackets.
  if (host_.find(':') != std::string::npos) {
    DCHECK_NE(host_[0], '[');
    return StringPrintf("[%s]:%u", host_.c_str(), port_);
  }
  return StringPrintf("%s:%u", host_.c_str(), port_);
}

}  // namespace net