bes  Updated for version 3.20.6
url_parser.cc
1 
2 // https://stackoverflow.com/questions/2616011/easy-way-to-parse-a-url-in-c-cross-platform
3 
4 #include <string>
5 #include <algorithm>
6 #include <cctype>
7 #include <functional>
8 
9 #include "url_parser.h"
10 
11 using namespace std;
12 
13 namespace AWSV4 {
14 
15 void url_parser::parse(const string &url_s) {
16  const string prot_end("://");
17  string::const_iterator prot_i = search(url_s.begin(), url_s.end(),
18  prot_end.begin(), prot_end.end());
19  protocol_.reserve(distance(url_s.begin(), prot_i));
20  transform(url_s.begin(), prot_i,
21  back_inserter(protocol_),
22  ptr_fun<int, int>(tolower)); // protocol is icase
23  if (prot_i == url_s.end())
24  return;
25  advance(prot_i, prot_end.length());
26  string::const_iterator path_i = find(prot_i, url_s.end(), '/');
27  host_.reserve(distance(prot_i, path_i));
28  transform(prot_i, path_i,
29  back_inserter(host_),
30  ptr_fun<int, int>(tolower)); // host is icase
31  string::const_iterator query_i = find(path_i, url_s.end(), '?');
32  path_.assign(path_i, query_i);
33  if (query_i != url_s.end())
34  ++query_i;
35  query_.assign(query_i, url_s.end());
36 }
37 
38 } // namespace AWSV4