]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/str_list.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / include / str_list.h
1 #ifndef CEPH_STRLIST_H
2 #define CEPH_STRLIST_H
3
4 #include <list>
5 #include <set>
6 #include <string>
7 #include <vector>
8
9 /**
10 * Split **str** into a list of strings, using the ";,= \t" delimiters and output the result in **str_list**.
11 *
12 * @param [in] str String to split and save as list
13 * @param [out] str_list List modified containing str after it has been split
14 **/
15 extern void get_str_list(const std::string& str,
16 std::list<std::string>& str_list);
17
18 /**
19 * Split **str** into a list of strings, using the **delims** delimiters and output the result in **str_list**.
20 *
21 * @param [in] str String to split and save as list
22 * @param [in] delims characters used to split **str**
23 * @param [out] str_list List modified containing str after it has been split
24 **/
25 extern void get_str_list(const std::string& str,
26 const char *delims,
27 std::list<std::string>& str_list);
28
29 /**
30 * Split **str** into a list of strings, using the ";,= \t" delimiters and output the result in **str_vec**.
31 *
32 * @param [in] str String to split and save as Vector
33 * @param [out] str_vec Vector modified containing str after it has been split
34 **/
35 extern void get_str_vec(const std::string& str,
36 std::vector<std::string>& str_vec);
37
38 /**
39 * Split **str** into a list of strings, using the **delims** delimiters and output the result in **str_vec**.
40 *
41 * @param [in] str String to split and save as Vector
42 * @param [in] delims characters used to split **str**
43 * @param [out] str_vec Vector modified containing str after it has been split
44 **/
45 extern void get_str_vec(const std::string& str,
46 const char *delims,
47 std::vector<std::string>& str_vec);
48
49 /**
50 * Split **str** into a list of strings, using the ";,= \t" delimiters and output the result in **str_list**.
51 *
52 * @param [in] str String to split and save as Set
53 * @param [out] str_list Set modified containing str after it has been split
54 **/
55 extern void get_str_set(const std::string& str,
56 std::set<std::string>& str_list);
57
58 /**
59 * Split **str** into a list of strings, using the **delims** delimiters and output the result in **str_list**.
60 *
61 * @param [in] str String to split and save as Set
62 * @param [in] delims characters used to split **str**
63 * @param [out] str_list Set modified containing str after it has been split
64 **/
65 extern void get_str_set(const std::string& str,
66 const char *delims,
67 std::set<std::string>& str_list);
68
69 /**
70 * Return a String containing the vector **v** joined with **sep**
71 *
72 * If **v** is empty, the function returns an empty string
73 * For each element in **v**,
74 * it will concatenate this element and **sep** with result
75 *
76 * @param [in] v Vector to join as a String
77 * @param [in] sep String used to join each element from **v**
78 * @return empty string if **v** is empty or concatenated string
79 **/
80 inline std::string str_join(const std::vector<std::string>& v, std::string sep)
81 {
82 if (v.empty())
83 return std::string();
84 std::vector<std::string>::const_iterator i = v.begin();
85 std::string r = *i;
86 for (++i; i != v.end(); ++i) {
87 r += sep;
88 r += *i;
89 }
90 return r;
91 }
92
93 static inline std::vector<std::string> get_str_vec(const std::string& str)
94 {
95 std::vector<std::string> str_vec;
96 const char *delims = ";,= \t";
97 get_str_vec(str, delims, str_vec);
98 return str_vec;
99 }
100
101 #endif