57 lines
1.0 KiB
C++
Raw Normal View History

2022-05-21 19:58:09 +02:00
#include "stdafx.h"
#include "Uri.h"
namespace Net
{
Uri::Uri(const char* Url)
: Uri(String(Url))
2022-05-21 19:58:09 +02:00
{
}
Uri::Uri(const String& Url)
2022-05-21 19:58:09 +02:00
: InternetPort(InternetPortType::Default), Host(""), Path("")
{
this->ParseUri(Url);
}
String Uri::GetUrl()
2022-05-21 19:58:09 +02:00
{
auto Base = (InternetPort == InternetPortType::Http) ? "http://" : "https://";
return Base + Host + Path;
}
void Uri::ParseUri(const String& Url)
2022-05-21 19:58:09 +02:00
{
auto LowerCaseUrl = Url.ToLower();
uint32_t ParsePoint = 0;
if (LowerCaseUrl.StartsWith("https://"))
{
this->InternetPort = InternetPortType::Https;
ParsePoint = 8;
}
else if (LowerCaseUrl.StartsWith("http://"))
{
this->InternetPort = InternetPortType::Http;
ParsePoint = 7;
}
else if (LowerCaseUrl.StartsWith("//"))
{
ParsePoint = 2;
}
auto PathStart = Url.IndexOf("/", ParsePoint);
if (PathStart != String::InvalidPosition)
2022-05-21 19:58:09 +02:00
{
this->Host = Url.SubString(ParsePoint, PathStart - ParsePoint);
this->Path = Url.SubString(PathStart + 1);
2022-05-21 19:58:09 +02:00
}
else
{
this->Host = Url.SubString(ParsePoint);
2022-05-21 19:58:09 +02:00
}
}
}