Kawe Mazidjatari 04bee896be Fix string/wstring type conflict
cppkore uses string/wstring as StringBase while we use std::string/std::wstring as string/wstring. Changed all types in cppkore to String/WString instead.
2022-05-21 21:51:35 +02:00

57 lines
1.0 KiB
C++

#include "stdafx.h"
#include "Uri.h"
namespace Net
{
Uri::Uri(const char* Url)
: Uri(String(Url))
{
}
Uri::Uri(const String& Url)
: InternetPort(InternetPortType::Default), Host(""), Path("")
{
this->ParseUri(Url);
}
String Uri::GetUrl()
{
auto Base = (InternetPort == InternetPortType::Http) ? "http://" : "https://";
return Base + Host + Path;
}
void Uri::ParseUri(const String& Url)
{
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)
{
this->Host = Url.SubString(ParsePoint, PathStart - ParsePoint);
this->Path = Url.SubString(PathStart + 1);
}
else
{
this->Host = Url.SubString(ParsePoint);
}
}
}