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