MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / parse_url

Method parse_url

modules/gui/gui/src/backend/text_server/ustring.cpp:258–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256/*************************************************************************/
257
258Error String::parse_url(String& r_scheme, String& r_host, int& r_port, String& r_path) const
259{
260 // Splits the URL into scheme, host, port, path. Strip credentials when present.
261 String base = *this;
262 r_scheme = "";
263 r_host = "";
264 r_port = 0;
265 r_path = "";
266 int pos = base.find("://");
267 // Scheme
268 if (pos != -1)
269 {
270 r_scheme = base.substr(0, pos + 3).to_lower();
271 base = base.substr(pos + 3, base.length() - pos - 3);
272 }
273 pos = base.find("/");
274 // Path
275 if (pos != -1)
276 {
277 r_path = base.substr(pos, base.length() - pos);
278 base = base.substr(0, pos);
279 }
280 // Host
281 pos = base.find("@");
282 if (pos != -1)
283 {
284 // Strip credentials
285 base = base.substr(pos + 1, base.length() - pos - 1);
286 }
287 if (base.begins_with("["))
288 {
289 // Literal IPv6
290 pos = base.rfind("]");
291 if (pos == -1)
292 {
293 return ERR_INVALID_PARAMETER;
294 }
295 r_host = base.substr(1, pos - 1);
296 base = base.substr(pos + 1, base.length() - pos - 1);
297 }
298 else
299 {
300 // Anything else
301 if (base.get_slice_count(":") > 2)
302 {
303 return ERR_INVALID_PARAMETER;
304 }
305 pos = base.rfind(":");
306 if (pos == -1)
307 {
308 r_host = base;
309 base = "";
310 }
311 else
312 {
313 r_host = base.substr(0, pos);
314 base = base.substr(pos, base.length() - pos);
315 }

Callers

nothing calls this directly

Calls 10

to_lowerMethod · 0.80
begins_withMethod · 0.80
get_slice_countMethod · 0.80
is_valid_intMethod · 0.80
findMethod · 0.45
substrMethod · 0.45
lengthMethod · 0.45
rfindMethod · 0.45
is_emptyMethod · 0.45
to_intMethod · 0.45

Tested by

no test coverage detected