]> git.proxmox.com Git - ceph.git/blob - ceph/src/dmclock/sim/src/str_list.h
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / dmclock / sim / src / str_list.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 /*
5 * Copyright (C) 2009 Red Hat Inc.
6 *
7 * Forked from Red Hat's Ceph project.
8 *
9 * This is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License version
11 * 2.1, as published by the Free Software Foundation. See file
12 * COPYING.
13 */
14
15
16 #ifndef CEPH_STRLIST_H
17 #define CEPH_STRLIST_H
18
19 #include <list>
20 #include <set>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24
25 /**
26 * Split **str** into a list of strings, using the ";,= \t" delimiters and output the result in **str_list**.
27 *
28 * @param [in] str String to split and save as list
29 * @param [out] str_list List modified containing str after it has been split
30 **/
31 extern void get_str_list(const std::string& str,
32 std::list<std::string>& str_list);
33
34 /**
35 * Split **str** into a list of strings, using the **delims** delimiters and output the result in **str_list**.
36 *
37 * @param [in] str String to split and save as list
38 * @param [in] delims characters used to split **str**
39 * @param [out] str_list List modified containing str after it has been split
40 **/
41 extern void get_str_list(const std::string& str,
42 const char *delims,
43 std::list<std::string>& str_list);
44
45 /**
46 * Split **str** into a list of strings, using the ";,= \t" delimiters and output the result in **str_vec**.
47 *
48 * @param [in] str String to split and save as Vector
49 * @param [out] str_vec Vector modified containing str after it has been split
50 **/
51 extern void get_str_vec(const std::string& str,
52 std::vector<std::string>& str_vec);
53
54 /**
55 * Split **str** into a list of strings, using the **delims** delimiters and output the result in **str_vec**.
56 *
57 * @param [in] str String to split and save as Vector
58 * @param [in] delims characters used to split **str**
59 * @param [out] str_vec Vector modified containing str after it has been split
60 **/
61 extern void get_str_vec(const std::string& str,
62 const char *delims,
63 std::vector<std::string>& str_vec);
64
65 /**
66 * Split **str** into a list of strings, using the ";,= \t" delimiters and output the result in **str_list**.
67 *
68 * @param [in] str String to split and save as Set
69 * @param [out] str_list Set modified containing str after it has been split
70 **/
71 extern void get_str_set(const std::string& str,
72 std::set<std::string>& str_list);
73
74 /**
75 * Split **str** into a list of strings, using the **delims** delimiters and output the result in **str_list**.
76 *
77 * @param [in] str String to split and save as Set
78 * @param [in] delims characters used to split **str**
79 * @param [out] str_list Set modified containing str after it has been split
80 **/
81 extern void get_str_set(const std::string& str,
82 const char *delims,
83 std::set<std::string>& str_list);
84
85 /**
86 * Return a String containing the vector **v** joined with **sep**
87 *
88 * If **v** is empty, the function returns an empty string
89 * For each element in **v**,
90 * it will concatenate this element and **sep** with result
91 *
92 * @param [in] v Vector to join as a String
93 * @param [in] sep String used to join each element from **v**
94 * @return empty string if **v** is empty or concatenated string
95 **/
96 inline std::string str_join(const std::vector<std::string>& v, const std::string& sep)
97 {
98 if (v.empty())
99 return std::string();
100 std::vector<std::string>::const_iterator i = v.begin();
101 std::string r = *i;
102 for (++i; i != v.end(); ++i) {
103 r += sep;
104 r += *i;
105 }
106 return r;
107 }
108
109 #endif