Fixed URLs with non-default char types.

This commit is contained in:
Patrick 2024-08-20 00:35:19 +02:00
parent 03f255a7d0
commit 05f0e1474a
2 changed files with 21 additions and 12 deletions

View File

@ -79,7 +79,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
}
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)
{
clear();
@ -88,7 +88,8 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
scheme_ = toParse.substr(0, pos);
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_ = {};
port_ = 0;
@ -96,7 +97,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
else
{
toParse = toParse.substr(2); // skip the slashes
pos = toParse.find('/');
pos = toParse.find(TChar('/'));
if (!parseAuthority(toParse.substr(0, pos)))
{
clear();
@ -110,7 +111,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
toParse = toParse.substr(pos);
}
pathQueryFragment_ = toParse;
pos = toParse.find('#');
pos = toParse.find(TChar('#'));
if (pos == string_view_t::npos)
{
fragment_ = {};
@ -120,7 +121,7 @@ constexpr void URLBase<TChar, TTraits, TAllocator>::parse() noexcept
fragment_ = toParse.substr(pos + 1);
toParse = toParse.substr(0, pos);
}
pos = toParse.find('?');
pos = toParse.find(TChar('?'));
if (pos == string_view_t::npos)
{
query_ = {};
@ -137,7 +138,7 @@ template<typename TChar, typename TTraits, typename TAllocator>
constexpr bool URLBase<TChar, TTraits, TAllocator>::parseAuthority(string_view_t authority) noexcept
{
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)
{
userinfo_ = {};
@ -147,7 +148,7 @@ constexpr bool URLBase<TChar, TTraits, TAllocator>::parseAuthority(string_view_t
userinfo_ = toParse.substr(0, pos);
toParse = toParse.substr(pos + 1);
}
pos = toParse.find(':'); // TODO: IPv6
pos = toParse.find(TChar(':')); // TODO: IPv6
if (pos == string_view_t::npos)
{
port_ = 0;

View File

@ -249,7 +249,7 @@ template<typename TLeft, typename TRight>
}
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)
{
@ -258,7 +258,7 @@ void makeLower(std::basic_string<TChar, TTraits, TAllocator>& string)
}
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)
{
@ -268,7 +268,7 @@ void makeUpper(std::basic_string<TChar, TTraits, TAllocator>& string)
template<typename... TArgs>
[[nodiscard]]
auto toLower(TArgs&&... args)
constexpr auto toLower(TArgs&&... args)
{
std::basic_string string(std::forward<TArgs>(args)...);
makeLower(string);
@ -277,7 +277,7 @@ auto toLower(TArgs&&... args)
template<typename... TArgs>
[[nodiscard]]
auto toUpper(TArgs&&... args)
constexpr auto toUpper(TArgs&&... args)
{
std::basic_string string(std::forward<TArgs>(args)...);
makeUpper(string);
@ -287,7 +287,7 @@ auto toUpper(TArgs&&... args)
template<typename TNumber>
[[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* 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;
}
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
{
struct Join