Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
azime committed Sep 19, 2022
1 parent 9a72248 commit 0d9f8ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
9 changes: 4 additions & 5 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ int str_to_int(std::string str) {
}

std::vector<std::string> split_string(const std::string& str, const std::string& separator) {
std::vector<std::string> SplitVec, to_return;
std::vector<std::string> SplitVec;
split(SplitVec, str, boost::is_any_of(separator), boost::token_compress_on);
for (std::string& data : SplitVec) {
boost::algorithm::trim(data);
if (!data.empty()) {
to_return.push_back(data);
}
}
return to_return;
boost::remove_erase_if(SplitVec,
[&](const std::string& str) { return str.empty(); });
return SplitVec;
}

std::string value_by_key(const std::map<std::string, std::string>& vect, const std::string& key) {
Expand Down
20 changes: 11 additions & 9 deletions tests/functions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,22 @@ BOOST_AUTO_TEST_CASE(trim) {
}

BOOST_AUTO_TEST_CASE(trim_without_comma) {
std::string test(" ab ");
std::vector<std::string> res = split_string(test, ";");
BOOST_CHECK_EQUAL(res.at(0), "ab");
std::string test(" ab ");
std::vector<std::string> res = split_string(test, ";");
BOOST_CHECK_EQUAL(res.size(), 1);
BOOST_CHECK_EQUAL(res.at(0), "ab");
}

BOOST_AUTO_TEST_CASE(trim_empty_string) {
std::string test("");
std::vector<std::string> res = split_string(test, ";");
BOOST_CHECK_EQUAL(res.size(), 0);
std::string test("");
std::vector<std::string> res = split_string(test, ";");
BOOST_CHECK_EQUAL(res.size(), 0);
}

BOOST_AUTO_TEST_CASE(trim_comma_only) {
std::string test(";");
std::vector<std::string> res = split_string(test, ";");
BOOST_CHECK_EQUAL(res.size(), 0);
std::string test(";");
std::vector<std::string> res = split_string(test, ";");
BOOST_CHECK_EQUAL(res.size(), 0);
}


0 comments on commit 0d9f8ca

Please sign in to comment.