File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
src/tools/fdsdump/src/common Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 66namespace fdsdump {
77
88std::vector<std::string>
9- string_split (const std::string &str, const std::string &delimiter)
9+ string_split (
10+ const std::string &str,
11+ const std::string &delimiter,
12+ unsigned int max_pieces)
1013{
1114 std::vector<std::string> pieces;
1215 std::size_t pos = 0 ;
1316
1417 for (;;) {
18+ if (max_pieces > 0 && pieces.size () == max_pieces - 1 ) {
19+ pieces.emplace_back (str.begin () + pos, str.end ());
20+ break ;
21+ }
22+
1523 std::size_t next_pos = str.find (delimiter, pos);
1624 if (next_pos == std::string::npos) {
1725 pieces.emplace_back (str.begin () + pos, str.end ());
1826 break ;
1927 }
2028 pieces.emplace_back (str.begin () + pos, str.begin () + next_pos);
21- pos = next_pos + 1 ;
29+ pos = next_pos + delimiter. size () ;
2230 }
2331 return pieces;
2432}
Original file line number Diff line number Diff line change @@ -27,10 +27,14 @@ using shared_tsnapshot = std::shared_ptr<fds_tsnapshot_t>;
2727 * If no delimeter is found, the result contains only the original string.
2828 * @param str String to be splitted
2929 * @param delimiter String delimeter
30+ * @param max_pieces The maximum number of pieces (0 = no limit)
3031 * @return Vector of piecies.
3132 */
3233std::vector<std::string>
33- string_split (const std::string &str, const std::string &delimiter);
34+ string_split (
35+ const std::string &str,
36+ const std::string &delimiter,
37+ unsigned int max_pieces = 0 );
3438
3539/* *
3640 * @brief Split string by a delimiter from right.
You can’t perform that action at this time.
0 commit comments