feat support vector<string>
All checks were successful
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 59s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m12s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m16s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m16s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (pull_request) Successful in 1m8s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m31s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m36s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (pull_request) Successful in 53s
linux-x64-gcc / linux-gcc (push) Successful in 1m56s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (pull_request) Successful in 1m13s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (pull_request) Successful in 1m20s
linux-hisiv500-gcc / linux-gcc-hisiv500 (pull_request) Successful in 1m25s
linux-mips64-gcc / linux-gcc-mips64el (pull_request) Successful in 1m31s
linux-x64-gcc / linux-gcc (pull_request) Successful in 1m47s
All checks were successful
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 59s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m12s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m16s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m16s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (pull_request) Successful in 1m8s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m31s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m36s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (pull_request) Successful in 53s
linux-x64-gcc / linux-gcc (push) Successful in 1m56s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (pull_request) Successful in 1m13s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (pull_request) Successful in 1m20s
linux-hisiv500-gcc / linux-gcc-hisiv500 (pull_request) Successful in 1m25s
linux-mips64-gcc / linux-gcc-mips64el (pull_request) Successful in 1m31s
linux-x64-gcc / linux-gcc (pull_request) Successful in 1m47s
This commit is contained in:
parent
e63273fa2b
commit
cc133b70f5
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
namespace ulib {
|
namespace ulib {
|
||||||
std::string
|
std::string
|
||||||
StrJoin(std::vector<nonstd::string_view> &vec,
|
StrJoin(const std::vector<nonstd::string_view> &vec,
|
||||||
nonstd::string_view delimiter,
|
nonstd::string_view delimiter,
|
||||||
bool ignore_empty_str)
|
bool ignore_empty_str)
|
||||||
{
|
{
|
||||||
@ -26,4 +26,13 @@ StrJoin(std::vector<nonstd::string_view> &vec,
|
|||||||
return std::move(ss.str());
|
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
|
}// namespace ulib
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string_view.hpp>
|
#include <string_view.hpp>
|
||||||
#include <type_traits>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace ulib {
|
namespace ulib {
|
||||||
@ -21,7 +20,11 @@ Clamp(const T &value, const T &low, const T &high)
|
|||||||
return Clamp(value, low, high, std::less<T>{});
|
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 = ",",
|
nonstd::string_view delimiter = ",",
|
||||||
bool ignore_empty_str = true);
|
bool ignore_empty_str = true);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <ulib/utils/utils.h>
|
#include <ulib/utils/utils.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
TEST(Utils, Clamp)
|
TEST(Utils, Clamp)
|
||||||
{
|
{
|
||||||
@ -32,3 +33,19 @@ TEST(Utils, StrJoin)
|
|||||||
EXPECT_EQ(ulib::StrJoin(vec, ",", false), ",b,c");
|
EXPECT_EQ(ulib::StrJoin(vec, ",", false), ",b,c");
|
||||||
EXPECT_EQ(ulib::StrJoin(vec, ",", true), "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…
Reference in New Issue
Block a user