Fixed URLs with non-default char types.
This commit is contained in:
parent
03f255a7d0
commit
05f0e1474a
@ -79,7 +79,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
string_view_t toParse = base_;
|
string_view_t toParse = base_;
|
||||||
typename string_view_t::size_type pos = toParse.find(':');
|
typename string_view_t::size_type pos = toParse.find(TChar(':'));
|
||||||
if (pos == string_t::npos)
|
if (pos == string_t::npos)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
@ -88,7 +88,8 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
|
|||||||
scheme_ = toParse.substr(0, pos);
|
scheme_ = toParse.substr(0, pos);
|
||||||
toParse = toParse.substr(pos + 1);
|
toParse = toParse.substr(pos + 1);
|
||||||
|
|
||||||
if (!toParse.starts_with("//"))
|
const TChar DOUBLE_SLASH[] = {TChar('/'), TChar('/'), TChar(0)};
|
||||||
|
if (!toParse.starts_with(DOUBLE_SLASH))
|
||||||
{
|
{
|
||||||
userinfo_ = host_ = {};
|
userinfo_ = host_ = {};
|
||||||
port_ = 0;
|
port_ = 0;
|
||||||
@ -96,7 +97,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
toParse = toParse.substr(2); // skip the slashes
|
toParse = toParse.substr(2); // skip the slashes
|
||||||
pos = toParse.find('/');
|
pos = toParse.find(TChar('/'));
|
||||||
if (!parseAuthority(toParse.substr(0, pos)))
|
if (!parseAuthority(toParse.substr(0, pos)))
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
@ -110,7 +111,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
|
|||||||
toParse = toParse.substr(pos);
|
toParse = toParse.substr(pos);
|
||||||
}
|
}
|
||||||
pathQueryFragment_ = toParse;
|
pathQueryFragment_ = toParse;
|
||||||
pos = toParse.find('#');
|
pos = toParse.find(TChar('#'));
|
||||||
if (pos == string_view_t::npos)
|
if (pos == string_view_t::npos)
|
||||||
{
|
{
|
||||||
fragment_ = {};
|
fragment_ = {};
|
||||||
@ -120,7 +121,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
|
|||||||
fragment_ = toParse.substr(pos + 1);
|
fragment_ = toParse.substr(pos + 1);
|
||||||
toParse = toParse.substr(0, pos);
|
toParse = toParse.substr(0, pos);
|
||||||
}
|
}
|
||||||
pos = toParse.find('?');
|
pos = toParse.find(TChar('?'));
|
||||||
if (pos == string_view_t::npos)
|
if (pos == string_view_t::npos)
|
||||||
{
|
{
|
||||||
query_ = {};
|
query_ = {};
|
||||||
@ -137,7 +138,7 @@ template<typename TChar, typename TTraits, typename TAllocator>
|
|||||||
constexpr bool URLBase<TChar, TTraits, TAllocator>::parseAuthority(string_view_t authority) noexcept
|
constexpr bool URLBase<TChar, TTraits, TAllocator>::parseAuthority(string_view_t authority) noexcept
|
||||||
{
|
{
|
||||||
string_view_t toParse = authority;
|
string_view_t toParse = authority;
|
||||||
typename string_view_t::size_type pos = toParse.find('@');
|
typename string_view_t::size_type pos = toParse.find(TChar('@'));
|
||||||
if (pos == string_view_t::npos)
|
if (pos == string_view_t::npos)
|
||||||
{
|
{
|
||||||
userinfo_ = {};
|
userinfo_ = {};
|
||||||
@ -147,7 +148,7 @@ constexpr bool URLBase<TChar, TTraits, TAllocator>::parseAuthority(string_view_t
|
|||||||
userinfo_ = toParse.substr(0, pos);
|
userinfo_ = toParse.substr(0, pos);
|
||||||
toParse = toParse.substr(pos + 1);
|
toParse = toParse.substr(pos + 1);
|
||||||
}
|
}
|
||||||
pos = toParse.find(':'); // TODO: IPv6
|
pos = toParse.find(TChar(':')); // TODO: IPv6
|
||||||
if (pos == string_view_t::npos)
|
if (pos == string_view_t::npos)
|
||||||
{
|
{
|
||||||
port_ = 0;
|
port_ = 0;
|
||||||
|
@ -249,7 +249,7 @@ template<typename TLeft, typename TRight>
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TChar, typename TTraits, typename TAllocator>
|
template<typename TChar, typename TTraits, typename TAllocator>
|
||||||
void makeLower(std::basic_string<TChar, TTraits, TAllocator>& string)
|
constexpr void makeLower(std::basic_string<TChar, TTraits, TAllocator>& string)
|
||||||
{
|
{
|
||||||
std::transform(string.begin(), string.end(), string.begin(), [locale = std::locale()](TChar chr)
|
std::transform(string.begin(), string.end(), string.begin(), [locale = std::locale()](TChar chr)
|
||||||
{
|
{
|
||||||
@ -258,7 +258,7 @@ void makeLower(std::basic_string<TChar, TTraits, TAllocator>& string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TChar, typename TTraits, typename TAllocator>
|
template<typename TChar, typename TTraits, typename TAllocator>
|
||||||
void makeUpper(std::basic_string<TChar, TTraits, TAllocator>& string)
|
constexpr void makeUpper(std::basic_string<TChar, TTraits, TAllocator>& string)
|
||||||
{
|
{
|
||||||
std::transform(string.begin(), string.end(), string.begin(), [locale = std::locale()](TChar chr)
|
std::transform(string.begin(), string.end(), string.begin(), [locale = std::locale()](TChar chr)
|
||||||
{
|
{
|
||||||
@ -268,7 +268,7 @@ void makeUpper(std::basic_string<TChar, TTraits, TAllocator>& string)
|
|||||||
|
|
||||||
template<typename... TArgs>
|
template<typename... TArgs>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
auto toLower(TArgs&&... args)
|
constexpr auto toLower(TArgs&&... args)
|
||||||
{
|
{
|
||||||
std::basic_string string(std::forward<TArgs>(args)...);
|
std::basic_string string(std::forward<TArgs>(args)...);
|
||||||
makeLower(string);
|
makeLower(string);
|
||||||
@ -277,7 +277,7 @@ auto toLower(TArgs&&... args)
|
|||||||
|
|
||||||
template<typename... TArgs>
|
template<typename... TArgs>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
auto toUpper(TArgs&&... args)
|
constexpr auto toUpper(TArgs&&... args)
|
||||||
{
|
{
|
||||||
std::basic_string string(std::forward<TArgs>(args)...);
|
std::basic_string string(std::forward<TArgs>(args)...);
|
||||||
makeUpper(string);
|
makeUpper(string);
|
||||||
@ -287,7 +287,7 @@ auto toUpper(TArgs&&... args)
|
|||||||
|
|
||||||
template<typename TNumber>
|
template<typename TNumber>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool toNumber(std::string_view stringView, TNumber& outNumber, int base = 10) noexcept
|
constexpr bool toNumber(std::string_view stringView, TNumber& outNumber, int base = 10) noexcept
|
||||||
{
|
{
|
||||||
const char* start = &*stringView.begin();
|
const char* start = &*stringView.begin();
|
||||||
const char* end = start + stringView.size();
|
const char* end = start + stringView.size();
|
||||||
@ -295,6 +295,14 @@ bool toNumber(std::string_view stringView, TNumber& outNumber, int base = 10) no
|
|||||||
return res.ec == std::errc{} && res.ptr == end;
|
return res.ec == std::errc{} && res.ptr == end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename TChar, typename TTraits, typename TNumber>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr bool toNumber(std::basic_string_view<TChar, TTraits> stringView, TNumber& outNumber, int base = 10) noexcept requires (!std::is_same_v<TChar, char>)
|
||||||
|
{
|
||||||
|
std::string asString(stringView.begin(), stringView.end());
|
||||||
|
return toNumber(asString, outNumber, base);
|
||||||
|
}
|
||||||
|
|
||||||
namespace pipe
|
namespace pipe
|
||||||
{
|
{
|
||||||
struct Join
|
struct Join
|
||||||
|
Loading…
x
Reference in New Issue
Block a user