Commit 8dd0e3e9 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

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
parent ae1594ea
......@@ -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 <class String>
......@@ -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<std::pair<fbstring, fbstring>>& Uri::getQueryParams() {
const std::vector<std::pair<std::string, std::string>>& Uri::getQueryParams() {
if (!query_.empty() && queryParams_.empty()) {
// Parse query string
static const boost::regex queryParamRegex(
......@@ -150,8 +150,8 @@ const std::vector<std::pair<fbstring, fbstring>>& 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
);
}
}
......
......@@ -17,9 +17,11 @@
#pragma once
#define FOLLY_URI_H_
#include <folly/String.h>
#include <string>
#include <vector>
#include <folly/String.h>
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 <class String>
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<std::pair<fbstring, fbstring>>& getQueryParams();
const std::vector<std::pair<std::string, std::string>>& 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<std::pair<fbstring, fbstring>> queryParams_;
std::string path_;
std::string query_;
std::string fragment_;
std::vector<std::pair<std::string, std::string>> queryParams_;
};
} // namespace folly
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment