Skip to content

Commit d2cc91d

Browse files
committed
Added join #7
1 parent adab4b2 commit d2cc91d

File tree

8 files changed

+63
-1
lines changed

8 files changed

+63
-1
lines changed

src/wsjcpp_core.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,19 @@ std::vector<std::string> WSJCppCore::split(const std::string& sWhat, const std::
482482

483483
// ---------------------------------------------------------------------
484484

485+
std::string WSJCppCore::join(const std::vector<std::string> &vWhat, const std::string& sDelim) {
486+
std::string sRet;
487+
for (int i = 0; i < vWhat.size(); i++) {
488+
if (i != 0) {
489+
sRet += sDelim;
490+
}
491+
sRet += vWhat[i];
492+
}
493+
return sRet;
494+
}
495+
496+
// ---------------------------------------------------------------------
497+
485498
void WSJCppCore::initRandom() {
486499
std::srand(std::rand() + std::time(0));
487500
}

src/wsjcpp_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class WSJCppCore {
5050
static std::string toUpper(const std::string& str);
5151
static void replaceAll(std::string& str, const std::string& from, const std::string& to);
5252
static std::vector<std::string> split(const std::string& sWhat, const std::string& sDelim);
53+
static std::string join(const std::vector<std::string> &vWhat, const std::string& sDelim);
5354

5455
static void initRandom();
5556
static std::string createUuid();

unit-tests.wsjcpp/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ tmp/*
22
logs/*
33
unit-tests
44
.wsjcpp/*
5-
data/empty.txt
65

76
# Vim temp files
87
*.swp

unit-tests.wsjcpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_create_empty_fil
5757
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_create_empty_file.cpp")
5858
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_read_file_to_buffer.h")
5959
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_read_file_to_buffer.cpp")
60+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_join.h")
61+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_join.cpp")
6062

6163
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.user-custom.txt)
6264

unit-tests.wsjcpp/data/empty.txt

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "unit_test_join.h"
2+
#include <vector>
3+
#include <wsjcpp_core.h>
4+
5+
REGISTRY_UNIT_TEST(UnitTestJoin)
6+
7+
UnitTestJoin::UnitTestJoin()
8+
: WSJCppUnitTestBase("UnitTestJoin") {
9+
}
10+
11+
// ---------------------------------------------------------------------
12+
13+
void UnitTestJoin::init() {
14+
// nothing
15+
}
16+
17+
// ---------------------------------------------------------------------
18+
19+
bool UnitTestJoin::run() {
20+
bool bTestSuccess = true;
21+
std::vector<std::string> vTest;
22+
vTest.push_back("");
23+
vTest.push_back("1");
24+
vTest.push_back("2");
25+
vTest.push_back("abc");
26+
std::string sRet = WSJCppCore::join(vTest, ", ");
27+
compareS(bTestSuccess, "join", sRet, ", 1, 2, abc");
28+
return bTestSuccess;
29+
}
30+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef UNIT_TEST_JOIN_H
2+
#define UNIT_TEST_JOIN_H
3+
4+
#include <wsjcpp_unit_tests.h>
5+
6+
// Description: TODO
7+
class UnitTestJoin : public WSJCppUnitTestBase {
8+
public:
9+
UnitTestJoin();
10+
virtual void init();
11+
virtual bool run();
12+
};
13+
14+
#endif // UNIT_TEST_JOIN_H
15+

wsjcpp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ unit-tests:
6464
description: "Test create empty file"
6565
- name: "ReadFileToBuffer"
6666
description: "test for readFileToBuffer"
67+
- name: "Join"
68+
description: "Test join function"

0 commit comments

Comments
 (0)