From 8dd0e3e906589a991a1050f5c0c653d5740e3dd4 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Tue, 6 Jun 2017 19:53:27 -0700 Subject: [PATCH] Switch folly::Uri to use std::string rather than fbstring Summary: Using fbstring directly is not really worthwhile in the vast majority of cases, especially when most places just convert it into an `std::string` immediately. Reviewed By: yfeldblum Differential Revision: D5187835 fbshipit-source-id: 6f7d71612d3765e8b501d2432cd6281369bfe0fa --- folly/Uri.cpp | 18 +++++++++--------- folly/Uri.h | 40 +++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/folly/Uri.cpp b/folly/Uri.cpp index 9fc58280..03fe3a06 100644 --- a/folly/Uri.cpp +++ b/folly/Uri.cpp @@ -23,9 +23,9 @@ namespace folly { namespace { -fbstring submatch(const boost::cmatch& m, int idx) { +std::string submatch(const boost::cmatch& m, int idx) { auto& sub = m[idx]; - return fbstring(sub.first, sub.second); + return std::string(sub.first, sub.second); } template @@ -61,7 +61,7 @@ Uri::Uri(StringPiece str) : hasAuthority_(false), port_(0) { authorityAndPathRegex)) { // Does not start with //, doesn't have authority hasAuthority_ = false; - path_ = authorityAndPath.fbstr(); + path_ = authorityAndPath.str(); } else { static const boost::regex authorityRegex( "(?:([^@:]*)(?::([^@]*))?@)?" // username, password @@ -96,8 +96,8 @@ Uri::Uri(StringPiece str) : hasAuthority_(false), port_(0) { fragment_ = submatch(match, 4); } -fbstring Uri::authority() const { - fbstring result; +std::string Uri::authority() const { + std::string result; // Port is 5 characters max and we have up to 3 delimiters. result.reserve(host().size() + username().size() + password().size() + 8); @@ -123,7 +123,7 @@ fbstring Uri::authority() const { return result; } -fbstring Uri::hostname() const { +std::string Uri::hostname() const { if (host_.size() > 0 && host_[0] == '[') { // If it starts with '[', then it should end with ']', this is ensured by // regex @@ -132,7 +132,7 @@ fbstring Uri::hostname() const { return host_; } -const std::vector>& Uri::getQueryParams() { +const std::vector>& Uri::getQueryParams() { if (!query_.empty() && queryParams_.empty()) { // Parse query string static const boost::regex queryParamRegex( @@ -150,8 +150,8 @@ const std::vector>& Uri::getQueryParams() { continue; } queryParams_.emplace_back( - fbstring((*itr)[2].first, (*itr)[2].second), // parameter name - fbstring((*itr)[3].first, (*itr)[3].second) // parameter value + std::string((*itr)[2].first, (*itr)[2].second), // parameter name + std::string((*itr)[3].first, (*itr)[3].second) // parameter value ); } } diff --git a/folly/Uri.h b/folly/Uri.h index 09e2f677..6369d522 100644 --- a/folly/Uri.h +++ b/folly/Uri.h @@ -17,9 +17,11 @@ #pragma once #define FOLLY_URI_H_ -#include +#include #include +#include + namespace folly { /** @@ -45,14 +47,14 @@ class Uri { */ explicit Uri(StringPiece str); - const fbstring& scheme() const { return scheme_; } - const fbstring& username() const { return username_; } - const fbstring& password() const { return password_; } + const std::string& scheme() const { return scheme_; } + const std::string& username() const { return username_; } + const std::string& password() const { return password_; } /** * Get host part of URI. If host is an IPv6 address, square brackets will be * returned, for example: "[::1]". */ - const fbstring& host() const { return host_; } + const std::string& host() const { return host_; } /** * Get host part of URI. If host is an IPv6 address, square brackets will not * be returned, for exmaple "::1"; otherwise it returns the same thing as @@ -62,13 +64,13 @@ class Uri { * or API that connects to that host/port; e.g. getaddrinfo() only understands * IPv6 host without square brackets */ - fbstring hostname() const; + std::string hostname() const; uint16_t port() const { return port_; } - const fbstring& path() const { return path_; } - const fbstring& query() const { return query_; } - const fbstring& fragment() const { return fragment_; } + const std::string& path() const { return path_; } + const std::string& query() const { return query_; } + const std::string& fragment() const { return fragment_; } - fbstring authority() const; + std::string authority() const; template String toString() const; @@ -101,19 +103,19 @@ class Uri { * pair of which the first element is parameter name and the second * one is parameter value */ - const std::vector>& getQueryParams(); + const std::vector>& getQueryParams(); private: - fbstring scheme_; - fbstring username_; - fbstring password_; - fbstring host_; + std::string scheme_; + std::string username_; + std::string password_; + std::string host_; bool hasAuthority_; uint16_t port_; - fbstring path_; - fbstring query_; - fbstring fragment_; - std::vector> queryParams_; + std::string path_; + std::string query_; + std::string fragment_; + std::vector> queryParams_; }; } // namespace folly -- 2.34.1