7 std::string
strjoin(
const std::vector<std::string>& strings,
const std::string& delim) {
13 std::string output = strings[0];
14 for (
unsigned int i = 1; i < strings.size(); i++) {
15 output +=
format(
"%s%s", delim.c_str(), strings[i].c_str());
20 std::vector<std::string>
strsplit(
const std::string& s,
char del) {
21 std::vector<std::string> v;
22 std::string::const_iterator
i1 = s.begin(), i2;
24 i2 = std::find(
i1, s.end(), del);
25 v.push_back(std::string(
i1, i2));
26 if (i2 == s.end())
break;
32 #if defined(NO_FMTLIB)
33 std::string
format(
const char* fmt, ...) {
37 static void delarray(
char* p) {
41 shared_ptr<char> buffer(
new char[size], deleter::delarray);
44 int nsize = vsnprintf(buffer.get(), size, fmt, vl);
46 buffer.reset(
new char[++nsize], deleter::delarray);
47 nsize = vsnprintf(buffer.get(), nsize, fmt, vl);
54 #if defined(ENABLE_CATCH)
57 # include <catch2/catch_all.hpp>
61 TEST_CASE(
"Test endswith function",
"[endswith]") {
62 REQUIRE(
endswith(
"aaa",
"-PengRobinson") ==
false);
63 REQUIRE(
endswith(
"Ethylbenzene",
"-PengRobinson") ==
false);
64 REQUIRE(
endswith(
"Ethylbenzene-PengRobinson",
"-PengRobinson") ==
true);
65 REQUIRE(
endswith(
"Ethylbenzene",
"Ethylbenzene") ==
true);