feat support vector<string> #7
@ -3,7 +3,7 @@
|
||||
|
||||
namespace ulib {
|
||||
std::string
|
||||
StrJoin(std::vector<nonstd::string_view> &vec,
|
||||
StrJoin(const std::vector<nonstd::string_view> &vec,
|
||||
nonstd::string_view delimiter,
|
||||
bool ignore_empty_str)
|
||||
{
|
||||
@ -26,4 +26,13 @@ StrJoin(std::vector<nonstd::string_view> &vec,
|
||||
return std::move(ss.str());
|
||||
}
|
||||
|
||||
std::string
|
||||
StrJoin(const std::vector<std::string> &vec,
|
||||
nonstd::string_view delimiter,
|
||||
bool ignore_empty_str)
|
||||
{
|
||||
return StrJoin(std::vector<nonstd::string_view>{vec.cbegin(), vec.cend()},
|
||||
delimiter, ignore_empty_str);
|
||||
}
|
||||
|
||||
}// namespace ulib
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include <functional>
|
||||
#include <string_view.hpp>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace ulib {
|
||||
@ -21,7 +20,11 @@ Clamp(const T &value, const T &low, const T &high)
|
||||
return Clamp(value, low, high, std::less<T>{});
|
||||
}
|
||||
|
||||
std::string StrJoin(std::vector<nonstd::string_view> &vec,
|
||||
std::string StrJoin(const std::vector<nonstd::string_view> &vec,
|
||||
nonstd::string_view delimiter = ",",
|
||||
bool ignore_empty_str = true);
|
||||
|
||||
std::string StrJoin(const std::vector<std::string> &vec,
|
||||
nonstd::string_view delimiter = ",",
|
||||
bool ignore_empty_str = true);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <ulib/utils/utils.h>
|
||||
#include <vector>
|
||||
|
||||
TEST(Utils, Clamp)
|
||||
{
|
||||
@ -32,3 +33,19 @@ TEST(Utils, StrJoin)
|
||||
EXPECT_EQ(ulib::StrJoin(vec, ",", false), ",b,c");
|
||||
EXPECT_EQ(ulib::StrJoin(vec, ",", true), "b,c");
|
||||
}
|
||||
|
||||
TEST(Utils, StrJoin_vector_string)
|
||||
{
|
||||
std::vector<std::string> vec{"a", "b", "c"};
|
||||
EXPECT_EQ(ulib::StrJoin(vec, ","), "a,b,c");
|
||||
const std::vector<std::string> &const_vec = vec;
|
||||
EXPECT_EQ(ulib::StrJoin(const_vec, ","), "a,b,c");
|
||||
}
|
||||
|
||||
TEST(Utils, StrJoin_vector_nonstd_string_view)
|
||||
{
|
||||
std::vector<nonstd::string_view> vec{"a", "b", "c"};
|
||||
EXPECT_EQ(ulib::StrJoin(vec, ","), "a,b,c");
|
||||
const std::vector<nonstd::string_view> &const_vec = vec;
|
||||
EXPECT_EQ(ulib::StrJoin(const_vec, ","), "a,b,c");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user