X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FUri-inl.h;h=50d57c2ed53f2fccc01154d498749c885bc3d0a9;hp=71a23cbbda6ebd413426d718fdeffa427ea1fb6b;hb=3b8919b3c4121090183b40cd3fbcdeb81bf47645;hpb=9ff69037a4faab0ffb5e781b993428cceef62c9b diff --git a/folly/Uri-inl.h b/folly/Uri-inl.h index 71a23cbb..50d57c2e 100644 --- a/folly/Uri-inl.h +++ b/folly/Uri-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,22 +18,56 @@ #error This file may only be included from folly/Uri.h #endif -#include "folly/Conv.h" +#include +#include + +#include +#include namespace folly { +namespace uri_detail { + +using UriTuple = std::tuple< + const std::string&, + const std::string&, + const std::string&, + const std::string&, + uint16_t, + const std::string&, + const std::string&, + const std::string&>; + +inline UriTuple as_tuple(const folly::Uri& k) { + return UriTuple( + k.scheme(), + k.username(), + k.password(), + k.host(), + k.port(), + k.path(), + k.query(), + k.fragment()); +} + +} // namespace uri_detail + template String Uri::toString() const { String str; - toAppend(scheme_, "://", &str); - if (!password_.empty()) { - toAppend(username_, ":", password_, "@", &str); - } else if (!username_.empty()) { - toAppend(username_, "@", &str); - } - toAppend(host_, &str); - if (port_ != 0) { - toAppend(":", port_, &str); + if (hasAuthority_) { + toAppend(scheme_, "://", &str); + if (!password_.empty()) { + toAppend(username_, ":", password_, "@", &str); + } else if (!username_.empty()) { + toAppend(username_, "@", &str); + } + toAppend(host_, &str); + if (port_ != 0) { + toAppend(":", port_, &str); + } + } else { + toAppend(scheme_, ":", &str); } toAppend(path_, &str); if (!query_.empty()) { @@ -45,5 +79,23 @@ String Uri::toString() const { return str; } -} // namespace folly +} // namespace folly + +namespace std { + +template <> +struct hash { + std::size_t operator()(const folly::Uri& k) const { + return std::hash{}( + folly::uri_detail::as_tuple(k)); + } +}; + +template <> +struct equal_to { + bool operator()(const folly::Uri& a, const folly::Uri& b) const { + return folly::uri_detail::as_tuple(a) == folly::uri_detail::as_tuple(b); + } +}; +} // namespace std