diff options
| -rw-r--r-- | dev/lib/net/url.hpp | 59 | ||||
| -rw-r--r-- | dev/lib/tests/hpptest.hpp | 4 | ||||
| -rw-r--r-- | dev/lib/utility/embfs.hpp | 3 |
3 files changed, 45 insertions, 21 deletions
diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index 6772ac4..52991f2 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -11,42 +11,67 @@ #include <sstream> /// @author Amlal El Mahrouss (amlal@nekernel.org) +/// @brief Parse URLs (in a non-standard way). namespace scl::net { template <typename char_type> class basic_url; - template <typename char_type> - class basic_url_traits; + enum class url_protocol + { + invalid = 0, + http, + https, + mailto, + bad = 0xff, + }; /// @brief Basic URL parser container. template <typename char_type> class basic_url final { - friend basic_url_traits<char_type>; - - std::basic_stringstream<char_type> ss_{}; + url_protocol m_protocol_{url_protocol::invalid}; + std::basic_stringstream<char_type> m_ss_{}; public: - explicit basic_url() = default; - ~basic_url() = default; + explicit basic_url(const std::basic_string<char_type>& protocol) + { + if (protocol.starts_with("https://")) + { + m_protocol_ = url_protocol::https; + this->operator/=(protocol.substr(strlen("https://"))); + } + else if (protocol.starts_with("http://")) + { + m_protocol_ = url_protocol::http; + this->operator/=(protocol.substr(strlen("http://"))); + } + else if (protocol.starts_with("mailto:")) + { + m_protocol_ = url_protocol::mailto; + this->operator/=(protocol.substr(strlen("mailto:"))); + } + } + + ~basic_url() = default; basic_url& operator=(const basic_url&) = default; basic_url(const basic_url&) = default; + private: basic_url& operator/=(const std::basic_string<char_type>& in) { if (in.empty()) return *this; - ss_ += in; + m_ss_ += in; return *this; } basic_url& operator/=(const char_type& in) { - ss_ += in; + m_ss_ += in; return *this; } @@ -55,17 +80,15 @@ namespace scl::net return this->is_valid(); } - bool is_valid() + public: + bool protocol_exists() { - return ss_.size() > 0; + return this->m_protocol_ != url_protocol::bad || this->m_protocol_ != url_protocol::invalid; } - }; - enum class protocol - { - http, - https, - mailto, - bad + bool is_valid() + { + return m_ss_.size() > 0 && this->protocol_exists(); + } }; } // namespace scl::net diff --git a/dev/lib/tests/hpptest.hpp b/dev/lib/tests/hpptest.hpp index 333ece3..63fc962 100644 --- a/dev/lib/tests/hpptest.hpp +++ b/dev/lib/tests/hpptest.hpp @@ -7,7 +7,6 @@ #pragma once -#ifdef SCL_HPPTEST namespace scl::hpptest { typedef bool condition_type; @@ -15,7 +14,8 @@ namespace scl::hpptest template <condition_type expr = true> consteval inline void must_pass() { +#ifdef SCL_HPPTEST SCL_HPPTEST_ASSERT(expr); +#endif } } // namespace scl::hpptest -#endif diff --git a/dev/lib/utility/embfs.hpp b/dev/lib/utility/embfs.hpp index 689082c..2738ae7 100644 --- a/dev/lib/utility/embfs.hpp +++ b/dev/lib/utility/embfs.hpp @@ -28,7 +28,7 @@ namespace scl::embfs inline constexpr const size_t _inode_arr_len = 12; inline constexpr const size_t _inode_lookup_len = 8; -#ifdef EMBFS_28BIT_LBA +#if defined(EMBFS_28BIT_LBA) typedef std::uint32_t lba_t; #elif defined(EMBFS_48BIT_LBA) typedef std::uint64_t lba_t; @@ -37,6 +37,7 @@ namespace scl::embfs #endif typedef std::int16_t sword_t; + typedef std::int32_t sdword_t; typedef std::uint8_t utf8_char_t; |
