flatten 20260225
This commit is contained in:
39
tjp/core/internet/join.hpp
Executable file
39
tjp/core/internet/join.hpp
Executable file
@@ -0,0 +1,39 @@
|
||||
// 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
|
||||
Reference in New Issue
Block a user