40 lines
649 B
C++
Executable File
40 lines
649 B
C++
Executable File
// TJP COPYRIGHT HEADER
|
|
|
|
#pragma once
|
|
|
|
#include <tjp/core/string/String.h>
|
|
#include <tjp/core/string/StringView+concat.hpp>
|
|
|
|
namespace tjp::core::internet {
|
|
|
|
inline
|
|
void join_(String &base, const StringView &url)
|
|
{
|
|
if (base.empty())
|
|
{
|
|
concat_(base, url);
|
|
}
|
|
else
|
|
if (!url.empty())
|
|
{
|
|
if (base.back() == '/' && url.front() == '/')
|
|
concat_(base, url.substr(1));
|
|
else
|
|
if (base.back() != '/' && url.front() != '/')
|
|
concat_(base, "/", url);
|
|
else
|
|
concat_(base, url);
|
|
}
|
|
}
|
|
|
|
template<typename ... Args>
|
|
String join(Args&& ...args)
|
|
{
|
|
String result;
|
|
(join_(result, std::forward<Args>(args)), ...);
|
|
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|