flatten 20260225
This commit is contained in:
72
tjp/core/string/join.hpp
Executable file
72
tjp/core/string/join.hpp
Executable file
@@ -0,0 +1,72 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../iterators/is_first.hpp"
|
||||
#include "to_string.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace tjp::core {
|
||||
|
||||
template <typename V, typename T>
|
||||
void join_(std::string &result, is_first &first, const V &delimiter, const T & sv)
|
||||
{
|
||||
for (auto &s : sv)
|
||||
{
|
||||
if (!first.check())
|
||||
result += delimiter;
|
||||
|
||||
result.insert(result.end(), s.begin(), s.end());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V, typename U, typename T>
|
||||
void join_(std::string &result, is_first &first, const V &delimiter, const U &u, const T & sv)
|
||||
{
|
||||
for (auto &s_ : sv)
|
||||
{
|
||||
auto s = u(s_);
|
||||
if (!first.check())
|
||||
result += delimiter;
|
||||
|
||||
result.insert(result.end(), s.begin(), s.end());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V, typename ... T>
|
||||
std::string join(const V &delimiter, T&& ... t)
|
||||
{
|
||||
std::string result;
|
||||
is_first first;
|
||||
|
||||
((join_(result, first, delimiter, t)),...) ;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename V, typename ... T>
|
||||
std::string join_values(const V &delimiter, T&& ... t)
|
||||
{
|
||||
std::string result;
|
||||
is_first first;
|
||||
|
||||
auto u = [](auto &v) { return to_string(v); };
|
||||
((join_(result, first, delimiter, u, t)),...) ;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename V, typename U, typename ... T>
|
||||
std::string join_with(const V &delimiter, U &&u, T&& ... t)
|
||||
{
|
||||
std::string result;
|
||||
is_first first;
|
||||
|
||||
((join_(result, first, delimiter, u, t)),...) ;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user