intial commit
This commit is contained in:
52
source/mijin/util/string.hpp
Normal file
52
source/mijin/util/string.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(MIJIN_UTIL_STRING_HPP_INCLUDED)
|
||||
#define MIJIN_UTIL_STRING_HPP_INCLUDED 1
|
||||
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
|
||||
//
|
||||
// public defines
|
||||
//
|
||||
|
||||
//
|
||||
// public constants
|
||||
//
|
||||
|
||||
//
|
||||
// public types
|
||||
//
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
template <typename TRange, typename TValue = typename TRange::value_type>
|
||||
std::string join(const TRange& elements, const char* const delimiter)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto first = std::begin(elements);
|
||||
auto last = std::end(elements);
|
||||
|
||||
if (first != last)
|
||||
{
|
||||
std::copy(first, std::prev(last), std::ostream_iterator<TValue>(oss, delimiter));
|
||||
first = prev(last);
|
||||
}
|
||||
if (first != last)
|
||||
{
|
||||
oss << *first;
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
} // namespace mijin
|
||||
|
||||
#endif // !defined(MIJIN_UTIL_STRING_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user