}
query_ = submatch(match, 3);
- if (!query_.empty()) {
- // Parse query string
- static const boost::regex queryParamRegex(
- "(^|&)([^=&]*)=?([^=&]*)(?=(&|$))");
- boost::cregex_iterator paramBeginItr(
- match[3].first,
- match[3].second,
- queryParamRegex);
- boost::cregex_iterator paramEndItr;
- for(auto itr = paramBeginItr; itr != paramEndItr; itr++) {
- if (itr->length(2) == 0) {
- // key is empty, ignore it
- continue;
- }
- queryParams_.emplace_back(
- fbstring((*itr)[2].first, (*itr)[2].second), // parameter name
- fbstring((*itr)[3].first, (*itr)[3].second) // parameter value
- );
- }
- }
fragment_ = submatch(match, 4);
}
return host_;
}
+const std::vector<std::pair<fbstring, fbstring>>& Uri::getQueryParams() {
+ if (!query_.empty() && queryParams_.empty()) {
+ // Parse query string
+ static const boost::regex queryParamRegex(
+ "(^|&)" /*start of query or start of parameter "&"*/
+ "([^=&]*)=?" /*parameter name and "=" if value is expected*/
+ "([^=&]*)" /*parameter value*/
+ "(?=(&|$))" /*forward reference, next should be end of query or
+ start of next parameter*/);
+ boost::cregex_iterator paramBeginItr(
+ query_.data(), query_.data() + query_.size(), queryParamRegex);
+ boost::cregex_iterator paramEndItr;
+ for (auto itr = paramBeginItr; itr != paramEndItr; itr++) {
+ if (itr->length(2) == 0) {
+ // key is empty, ignore it
+ continue;
+ }
+ queryParams_.emplace_back(
+ fbstring((*itr)[2].first, (*itr)[2].second), // parameter name
+ fbstring((*itr)[3].first, (*itr)[3].second) // parameter value
+ );
+ }
+ }
+ return queryParams_;
+}
+
} // namespace folly