@@ -51,8 +51,7 @@ class UrlParser
51
51
}
52
52
else
53
53
{
54
- scheme_ = std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
55
- url_.begin () + static_cast <std::string::difference_type>(pos));
54
+ scheme_ = url_.substr (cpos, pos - cpos);
56
55
cpos = pos + 3 ;
57
56
}
58
57
@@ -74,16 +73,19 @@ class UrlParser
74
73
{
75
74
// port missing. Used default 80 / 443
76
75
if (scheme_ == " http" )
76
+ {
77
77
port_ = 80 ;
78
- if (scheme_ == " https" )
78
+ }
79
+ else if (scheme_ == " https" )
80
+ {
79
81
port_ = 443 ;
82
+ }
80
83
}
81
84
else
82
85
{
83
86
// port present
84
87
is_port = true ;
85
- host_ = std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
86
- url_.begin () + static_cast <std::string::difference_type>(pos));
88
+ host_ = url_.substr (cpos, pos - cpos);
87
89
cpos = pos + 1 ;
88
90
}
89
91
pos = url_.find_first_of (" /?" , cpos);
@@ -92,30 +94,23 @@ class UrlParser
92
94
path_ = std::string (" /" ); // use default path
93
95
if (is_port)
94
96
{
95
- std::string port_str (
96
- url_.begin () + static_cast <std::string::difference_type>(cpos),
97
- url_.begin () + static_cast <std::string::difference_type>(url_.length ()));
98
-
99
- port_ = GetPort (port_str);
97
+ auto port_str = url_.substr (cpos, url_.length ());
98
+ port_ = GetPort (port_str);
100
99
}
101
100
else
102
101
{
103
- host_ =
104
- std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
105
- url_.begin () + static_cast <std::string::difference_type>(url_.length ()));
102
+ host_ = url_.substr (cpos, url_.length ());
106
103
}
107
104
return ;
108
105
}
109
106
if (is_port)
110
107
{
111
- std::string port_str (url_.begin () + static_cast <std::string::difference_type>(cpos),
112
- url_.begin () + static_cast <std::string::difference_type>(pos));
113
- port_ = GetPort (port_str);
108
+ auto port_str = url_.substr (cpos, pos - cpos);
109
+ port_ = GetPort (port_str);
114
110
}
115
111
else
116
112
{
117
- host_ = std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
118
- url_.begin () + static_cast <std::string::difference_type>(pos));
113
+ host_ = url_.substr (cpos, pos - cpos);
119
114
}
120
115
cpos = pos;
121
116
@@ -124,27 +119,21 @@ class UrlParser
124
119
pos = url_.find (' ?' , cpos);
125
120
if (pos == std::string::npos)
126
121
{
127
- path_ =
128
- std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
129
- url_.begin () + static_cast <std::string::difference_type>(url_.length ()));
122
+ path_ = url_.substr (cpos, url_.length ());
130
123
query_ = " " ;
131
124
}
132
125
else
133
126
{
134
- path_ = std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
135
- url_.begin () + static_cast <std::string::difference_type>(pos));
136
- cpos = pos + 1 ;
137
- query_ =
138
- std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
139
- url_.begin () + static_cast <std::string::difference_type>(url_.length ()));
127
+ path_ = url_.substr (cpos, pos - cpos);
128
+ cpos = pos + 1 ;
129
+ query_ = url_.substr (cpos, url_.length ());
140
130
}
141
131
return ;
142
132
}
143
133
path_ = std::string (" /" );
144
134
if (url_[cpos] == ' ?' )
145
135
{
146
- query_ = std::string (url_.begin () + static_cast <std::string::difference_type>(cpos),
147
- url_.begin () + static_cast <std::string::difference_type>(url_.length ()));
136
+ query_ = url_.substr (cpos, url_.length ());
148
137
}
149
138
}
150
139
0 commit comments