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