diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-29 18:17:47 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-29 18:18:59 +0100 |
| commit | 65254486efff0fd1bb78a48ff90b7713a5ce539f (patch) | |
| tree | 20ce02c12a74ba9e6cd382bf9c1f09a0c611cb4d /Private/Source/URL.cxx | |
| parent | f03986937db0b927da4b10554801e18e4dc7c43f (diff) | |
Kernel: Update TODO.
Src: Refactorings according to clang-format.
Meta: Update specification.
Public: Remove useless UIKit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/Source/URL.cxx')
| -rw-r--r-- | Private/Source/URL.cxx | 138 |
1 files changed, 63 insertions, 75 deletions
diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx index 0aa75ab9..02a3ec77 100644 --- a/Private/Source/URL.cxx +++ b/Private/Source/URL.cxx @@ -8,92 +8,80 @@ */ #include <CFKit/URL.hpp> -#include <NewKit/Utils.hpp> - #include <KernelKit/DebugOutput.hpp> +#include <NewKit/Utils.hpp> // Bugs = 0 -namespace hCore -{ - Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {} - - Url::~Url() = default; - - constexpr const char *kProtos[] = { - "https", // http with the secure. - "http", // http without the secure - "file", // filesystem protocol - "ftp", // file transfer protocol - "params", // system settings - "rsh", // remote shell (gui) - }; - - constexpr const int kUrlOutSz = 3; //! :// - constexpr const int kProtosCount = 8; - constexpr const int kRangeSz = 4096; - - static ErrorOr<StringView> url_extract_location(const char *url) - { - if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) - return ErrorOr<StringView>{-1}; - - StringView view(string_length(url)); - - SizeT i = 0; - bool scheme_found = false; - - for (; i < string_length(url); ++i) - { - if (!scheme_found) - { - for (int y = 0; kProtosCount; ++y) - { - if (string_in_string(view.CData(), kProtos[y])) - { - i += string_length(kProtos[y]) + kUrlOutSz; - scheme_found = true; - - break; - } - } - } - - view.Data()[i] = url[i]; - } +namespace hCore { +Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {} - return ErrorOr<StringView>(view); - } +Url::~Url() = default; - static ErrorOr<StringView> url_extract_protocol(const char *url) - { - if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) - return ErrorOr<StringView>{-1}; +constexpr const char *kProtos[] = { + "https", // http with the secure. + "http", // http without the secure + "file", // filesystem protocol + "ftp", // file transfer protocol + "params", // system settings + "rsh", // remote shell (gui) +}; - ErrorOr<StringView> view{ -1 }; - - return view; - } +constexpr const int kUrlOutSz = 3; //! :// +constexpr const int kProtosCount = 8; +constexpr const int kRangeSz = 4096; + +static ErrorOr<StringView> url_extract_location(const char *url) { + if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) + return ErrorOr<StringView>{-1}; - Ref<ErrorOr<StringView>> Url::Location() noexcept - { - const char *src = m_urlView.Leak().CData(); - auto loc = url_extract_location(src); + StringView view(string_length(url)); - if (!loc) - return {}; + SizeT i = 0; + bool scheme_found = false; - return Ref<ErrorOr<StringView>>(loc); + for (; i < string_length(url); ++i) { + if (!scheme_found) { + for (int y = 0; kProtosCount; ++y) { + if (string_in_string(view.CData(), kProtos[y])) { + i += string_length(kProtos[y]) + kUrlOutSz; + scheme_found = true; + + break; + } + } } - Ref<ErrorOr<StringView>> Url::Protocol() noexcept - { - const char *src = m_urlView.Leak().CData(); - auto loc = url_extract_protocol(src); + view.Data()[i] = url[i]; + } - if (!loc) - return {}; + return ErrorOr<StringView>(view); +} - return Ref<ErrorOr<StringView>>(loc); - } -} // namespace hCore +static ErrorOr<StringView> url_extract_protocol(const char *url) { + if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz) + return ErrorOr<StringView>{-1}; + + ErrorOr<StringView> view{-1}; + + return view; +} + +Ref<ErrorOr<StringView>> Url::Location() noexcept { + const char *src = m_urlView.Leak().CData(); + auto loc = url_extract_location(src); + + if (!loc) return {}; + + return Ref<ErrorOr<StringView>>(loc); +} + +Ref<ErrorOr<StringView>> Url::Protocol() noexcept { + const char *src = m_urlView.Leak().CData(); + auto loc = url_extract_protocol(src); + + if (!loc) return {}; + + return Ref<ErrorOr<StringView>>(loc); +} +} // namespace hCore |
