boost::cmatch match;
if (UNLIKELY(!boost::regex_match(str.begin(), str.end(), match, uriRegex))) {
- throw std::invalid_argument("invalid URI");
+ throw std::invalid_argument(to<std::string>("invalid URI ", str));
}
scheme_ = submatch(match, 1);
authority.second,
authorityMatch,
authorityRegex)) {
- throw std::invalid_argument("invalid URI authority");
+ throw std::invalid_argument(
+ to<std::string>("invalid URI authority ",
+ StringPiece(authority.first, authority.second)));
}
StringPiece port(authorityMatch[4].first, authorityMatch[4].second);
fragment_ = submatch(match, 4);
}
-fbstring
-Uri::authority() const
-{
- fbstring result(host());
+fbstring Uri::authority() const {
+ fbstring result;
- if (port() != 0) {
- result += fbstring(":") + to<fbstring>(port());
- }
+ // Port is 5 characters max and we have up to 3 delimiters.
+ result.reserve(host().size() + username().size() + password().size() + 8);
- if (!username().empty()) {
- fbstring userInformation(username());
+ if (!username().empty() || !password().empty()) {
+ result.append(username());
if (!password().empty()) {
- userInformation += fbstring(":") + password();
+ result.push_back(':');
+ result.append(password());
}
- result = userInformation + "@" + result;
+ result.push_back('@');
+ }
+
+ result.append(host());
+
+ if (port() != 0) {
+ result.push_back(':');
+ toAppend(port(), &result);
}
return result;