MCPcopy Create free account
hub / github.com/avast/retdec / split

Function split

src/utils/string.cpp:599–614  ·  view source on GitHub ↗

* @brief Splits the given string by a separator. * * @param[in] str String to be splitted. * @param[in] sep Separator to be used. * @param[in] trimWhitespace If @c true, trims whitespace around the separated * strings. * * For example, * @code * split("; a ; b ; c ;", ';', true) * @endcode * returns * @code * ["", "a", "b", "c", ""] * @endcode */

Source from the content-addressed store, hash-verified

597* @endcode
598*/
599std::vector<std::string> split(const std::string &str, char sep, bool trimWhitespace) {
600 std::vector<std::string> result;
601 std::stringstream ss(str);
602 std::string item;
603 while (std::getline(ss, item, sep)) {
604 result.push_back(trimWhitespace ? trim(item) : item);
605 }
606
607 // If the input string ends with the separator, we have to add another
608 // empty string to the result. Indeed, the above way throws it away.
609 if (!str.empty() && str.back() == sep) {
610 result.push_back("");
611 }
612
613 return result;
614}
615
616/**
617* @brief Unifies line ends in the given string to LF.

Callers 8

parseListOfOptsMethod · 0.85
getAddressFromNameFunction · 0.85
getOffsetFromNameFunction · 0.85
TEST_FFunction · 0.85

Calls 3

trimFunction · 0.85
emptyMethod · 0.45
backMethod · 0.45

Tested by 1

TEST_FFunction · 0.68