File tree Expand file tree Collapse file tree 2 files changed +94
-0
lines changed
Expand file tree Collapse file tree 2 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ #include < algorithm>
3+
4+ #include " common.hpp"
5+
6+ std::vector<std::string>
7+ string_split (const std::string &str, const std::string &delimiter)
8+ {
9+ std::vector<std::string> pieces;
10+ std::size_t pos = 0 ;
11+ for (;;) {
12+ std::size_t next_pos = str.find (delimiter, pos);
13+ if (next_pos == std::string::npos) {
14+ pieces.emplace_back (str.begin () + pos, str.end ());
15+ break ;
16+ }
17+ pieces.emplace_back (str.begin () + pos, str.begin () + next_pos);
18+ pos = next_pos + 1 ;
19+ }
20+ return pieces;
21+ }
22+
23+ void
24+ string_ltrim (std::string &str)
25+ {
26+ auto is_space = [](char ch) {
27+ return std::isspace (int (ch));
28+ };
29+
30+ auto first_char = std::find_if_not (str.begin (), str.end (), is_space);
31+ str.erase (str.begin (), first_char);
32+ }
33+
34+ void
35+ string_rtrim (std::string &str)
36+ {
37+ auto is_space = [](char ch) {
38+ return std::isspace (int (ch));
39+ };
40+
41+ auto last_char = std::find_if_not (str.rbegin (), str.rend (), is_space);
42+ str.erase (last_char.base (), str.end ());
43+ }
44+
45+ void
46+ string_trim (std::string &str)
47+ {
48+ string_rtrim (str);
49+ string_ltrim (str);
50+ }
51+
52+ std::string
53+ string_trim_copy (std::string str)
54+ {
55+ string_trim (str);
56+ return str;
57+ }
Original file line number Diff line number Diff line change 1+
2+ #pragma once
3+
4+ #include < memory>
5+ #include < string>
6+ #include < vector>
7+
8+ #include " libfds.h"
9+
10+ using unique_file = std::unique_ptr<fds_file_t , decltype (&fds_file_close)>;
11+ using unique_iemgr = std::unique_ptr<fds_iemgr_t , decltype (&fds_iemgr_destroy)>;
12+ using unique_filter = std::unique_ptr<fds_ipfix_filter, decltype (&fds_ipfix_filter_destroy)>;
13+ using shared_iemgr = std::shared_ptr<fds_iemgr_t >;
14+ using shared_tsnapshot = std::shared_ptr<fds_tsnapshot_t >;
15+
16+ /* *
17+ * @brief Split string using a user-defined delimeter.
18+ *
19+ * If no delimeter is found, the result contains only the original string.
20+ * @param str String to be splitted
21+ * @param delimiter String delimeter
22+ * @return Vector of piecies.
23+ */
24+ std::vector<std::string>
25+ string_split (const std::string &str, const std::string &delimiter);
26+
27+ void
28+ string_ltrim (std::string &str);
29+
30+ void
31+ string_rtrim (std::string &str);
32+
33+ void
34+ string_trim (std::string &str);
35+
36+ std::string
37+ string_trim_copy (std::string str);
You can’t perform that action at this time.
0 commit comments